C# Playing a sound from an URL - c#

I made a Windows Forms Application C# and I want to add music to it, I know how to do it if I have the file in my PC, but what if I want to send the application to a friend and he does not have the sound file what to do? Can you use an URL? Or resources? If yes, how to do it?
Thanks alot !

You can create a Windows Setup project and add all necessary files to distribute, including that sound file. The project can be found in Visual Studio under: Other Project Types ->Setup and Deployments: add it to your solution workspace in order to produce .msi and Setup.exe files. Alternatively, you can embed the file as a Resource (re: http://www.codeproject.com/Articles/17422/Embedding-and-Playing-WAV-Audio-Files-in-a-WinForm), but it may substantially increase the size of .exe file.

Your music file should be in your app file, but also you can play from url.
The best way is to keep it in your app, because the connection to the file will be faster. Here is one way to play from url: How to play .mp3 file from online resources in C#?

Related

How to transfer C# Windows form (.NET Framework) from one PC to another PC

As you could guess, I'm an absolute beginner to Visual Studios and C# Windows Forms (.NET Framework). I want to transfer my project from my laptop to my PC but I have no idea how to do so. I've been trying for quite a while but can't seem to get what files to copy. I'm copying the [Name].cs , [Name].Designer.cs and [Name].resx files but I can't seem to get them to work. should I copy the whole folder or .sln file or what?
Could anyone help me please?
Copy the whole root directory where the .sln is or .csproj if it is a single winforms project.
On the destination computer you might need some prerequisites.
If you want to be able to work on it and update it from both places, use GitHub and make a private repository. That's an easy way. The other way is follow the file path: C:\users\admin\source\repos and find your project in that list of folders. You could copy it to a flash drive, if you wanted to do it that way.

How do you "Build" an exe that includes all the resource files like pics? Can exe be put on a web page?

I have students in high school who have created some programs using Visual Studio C#. They created some games and would like to now upload them to the web. I am pretty new to Visual Studio C#. I thought after a program was "built" that you could go into the bin/debug folder and get the exe file for the program and be able to play the game without having to have Visual Studio on the actual computer you are playing it on. It works with some of their games but some of them, there are graphical files that are missing in the exe file if all the other files aren't stored in the same place. How can I get a clean exe of their game? Can that exe be loaded up onto a web server so they can play it from there or at least download it from there?
Microsoft wrote a guide on how to do exactly this. It's on their MSDN website, which is sort of like the developer back-bone for a lot of Microsoft software and documentation.
Old guide: Adding and Editing Resources (Visual C#)
Newer guide: How to: Add or Remove Resources
The gist is that the program needs to know where the files are, relative to the location of the compiled binary (in this case, an .EXE); There's several different ways to do this, depending on your level of expertise. I would suggest that you take a look at the guides above to start that journey.
there's a few ways of doing this. (Also, make sure you're creating a 'release' build when you compile).
You can include resources in your game by creating a resources file. This is something I usually do only on winforms applications etc.
If you have on-disk files you need to distribute those on-disk files along side your game. You could do this by zipping up your game.exe and the /files/images.img folder (or what ever your resources content folder is named).
If you're feeling adventurous you could create a 'deployment project' which is a project that allows you to create an installer file. This is a bit more work however you will have fine grained control over what files go where etc.
Good luck!
EXE files generally aren't self contained for video games with many resources, just add resources in an external folder and make sure the paths to the resources in their games are not absolute but relative in the local directory.
So for example:
get rid of paths like C:/Users/Bob/Desktop/Game/Images/player.png and replace with /Images/Player.png.
Also, an EXE generally doesn't run client side on webpages, it is possible but difficult. Things such as Flash are made for this sort of issue. I'd say make the webpage a place where they can download their games. Github has a nice way to do free websites called gh-pages. OFC, you could host one yourself but that would require a lot of setup work.
Like Monza said, you can zip up the files for download. Or, you could create an installer if you wanted to be really ambitious.
I thought after a program was "built" that you could go into the bin/debug folder and get the exe file for the program and be able to play the game without having to have Visual Studio on the actual computer you are playing it on.
That is correct, given that the other machine has the necessary .NET framework version installed AND any other resources like .dll files and config files are also present. When the application is ready for release, you can set the Build options in the project properties to Release, and then when you build all the files needed for distribution will be in the bin\Release folder.
It works with some of their games but some of them, there are graphical files that are missing in the exe file if all the other files aren't stored in the same place.
This may depend on how the application was written. If resources like pictures are embedded in the assembly then those files will not be needed to run on another machine. If the application is using hard coded paths for the image resources in the source code, then the application will likely break if the necessary files aren't present when the .exe is executed.
Can that exe be loaded up onto a web server so they can play it from there or at least download it from there?
Yes - you could upload the .exe to a file server to make available for a download, but you would not be able to run it within a browser over the web. I would recommend zipping up the .exe and other files needed and hosting the .zip file on the web server for download; browsers may give a warning or block downloading an .exe .
Hope this explains it a little bit for you.

Hide application files from user Visual C#

After installing my application on a clients machine, How can I securely hide files used by my program from the user? Such as pdf's and video files. I am using C# and windows forms in Visual Studio 2013.
Another option would be using a ZIP Package (see MSDN).
You can store your files in the package with CompressionOption.SuperFast or even CompressionOption.NotCompressed to maximize performance. All your files will be located in that package, and you will be able to modify and save them back.
Unfortunately, there is no option to encrypt nor password protect the package, and the user will be able to "open" your package in a ZIP tool (or even via Explorer), if he or she knows the file name and does understand that file extension doesn't matter.
As Matt commented, Embedded Resources is a way. Just remember that if you're currently navigating to your files (e.g. c:\MyApp\MyFile.pdf), you will not be able to do that anymore if you change these files to Embedded Resources.
Have a look at this Question.
You may also consider creating a Resource file (.resx) and adding your pdf's and videos into the resource file.
Managed to do it by converting all files to shock wave flash files and encrypting them. Then I could decrypt the files into a memory stream and display straight into a flash player.

Bundling 2 .exe's together in a C# application

I want to write an application that launches another app using Process.Start , but that app is a .exe, can I bundle that into my C# app without it being outside in a folder? I want to make it so my app doesn't need to install at all, so can it be in the app?
Not entirely sure if I understand, but do you mean so you can ship it and send it around as a single .exe (rather than zipping it all up)?
Could you embed the .exe in as an embedded resource and have your own .exe put it in some temporary files?
You want to make two exe's look like one exe?
There is no reasonable way to do this. Are you using someone else's program and don't want people to know?

Access SDExplorer (System Folder) from my C# app

I am trying out Windows Live SkyDrive, and I installed SDExplorer (http://www.cloudstorageexplorer.com/)
It works by adding my SkyDrive folder to Windows Explorer, but it does not get a drive name or anything, so how can I access that drive/folder from my C# application?
When I go into the folder and look at the address bar it says "Computer\SDExplorer".
Directory.GetDirectories(#"\Computer\SDExplorer") does not work, because it translates to "C:\Computer\SDExplorer".
I would like to be able to create a small application that can create folders and upload files to my SkyDrive account.
Anybody know how these special folder/drives work? - I noticed MozyHome appears in the same way in my Windows Explorer.
Some background info: http://www.technospot.net/blogs/how-to-create-a-system-folder-in-my-computer/
The SDExplorer folder is a system folder. You can find it in the registry at the following location
HKEY_CLASSES_ROOT\CLSID{0016CE0E-728C-4FC9-98E5-D0B35B384597}
Instead of using shell32.dll it uses C:\Program Files\SDExplorer\SDShellNSE.dll,0 with the parameter a0800018 instead of a normal path.
If my assumptions are correct, the folder location is hidden somewhere in that DLL file. I had a look with a hex editor but could not find anything useful.
Thanks a lot for your replies. Because I am interested in how this works I will try to dig a little deeper. Thanks for pointing me in the right direction.
I have managed to build my small application (made it into a service), which can create folders and upload files to SkyDrive. I did this without SDExplorer, and instead I used the SkyDrive .NET API someone build here: http://skydriveapiclient.codeplex.com/
Greetings
Søren

Categories