I am trying to play audio from a resource using .NET Compact Framework. I added an audio file for the resource property in my application and am trying to use the below sample resource file reference code for...
SoundPlayer player = new SoundPlayer(Assembly.GetExecutingAssembly().
GetManifestResourceStream("blessedwav.wav"));
player.Play();
But this code doesn't play a WAV sound. How do I play the resource audio file using .NET Compact Framework 3.5?
Open File Manager and navigate to the folder where the audio file is located. Drag the audio file icon from File Manager and drop it on the Audio main window. The Selected file is opened. If Automatically play audio file on Open is selected in the Options-Play dialog box, the audio file starts playing.
Since WAV is quite a popular format, almost all devices today support it using built-in media players. On Windows, the Windows Media Player is capable of playing WAV files. On MacOS, iTunes or QuickTime can play WAV files. On Linux, your basic ALSA system can play these files.
The audio files are stored in botht the res/raw directory and the asset directory.
I got the solution. This code is working very well in .NET Compact Framework:
// Convert a byte array to a stream
using (var audioStream = new MemoryStream(Properties.Resources.full_song_wav))
{
using (var player = new SoundPlayer(audioStream))
{
player.Play()
}
}
Try this:
//I added the file as a audio resource in my project
SoundPlayer player = new SoundPlayer(Properties.Resources.recycle);
player.Play();
I didn't try with .NET Compact Framework. But it is working for me in C#.
This should work for you:
Stream str = Properties.Resources.YourWaveSoundFile;
SoundPlayer plyr = new SoundPlayer(str);
plyr.Play();
Make sure you have using System.Media
above your namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With