Read [C# .NET] Play sounds like embedded resources.
Developing.pngOthers infos about System.Media namespace and embedded sounds in a resource file.

In a recent message I have dealt PlaySound method using InteropService.
This method work with a path and this is a source of various problems:

- You must specify a full or relative path and include in your dir app all sounds.

- Users can delete files!

You have a similar problem if your use PlaySound with a stream also.

So, is good idea to insert your sounds in a Resources File like this:

1. Add 'New Item' in your project.
2. Select 'Resource File'.
3. Add all your sounds here.

N.B. Set all wav files added like 'Embedded Resources' in 'Build Action' option in 'Properties Window'.

Now you can play all sounds like this:


using System.Media;
...

SoundPlayer snd_player = new SoundPlayer('RESOURCE_FILE_NAME'.'wav_name');
snd_player.Play();



'wav_name' is one wave added to your resource file that appears like Resource File public global variable.
'Play()' method play a wave in asynchronous mode, but you can play it in synchronous mode using 'PlaySync()' method.

--
Enjoy your sounds! :)


Posted Saturday 17 June 2006 - 16:24





Other news about this topic

Read [C# .NET] Moving WinForm without top-bar. (18/06/2006 - 20:37) read 111 times
Read [C# .NET] Develop C# Applications under Linux. (17/06/2006 - 16:43) read 79 times
Read [C# .NET] Play sounds like embedded resources. (17/06/2006 - 16:24) read 108 times
Read [C# .NET] Set Proxy in IE Component. (16/06/2006 - 01:55) read 98 times
Read [C# .NET] System.Media VS. PlaySound. (15/06/2006 - 18:36) read 112 times
Necrosoft Home

Calendar
Date: 27/11/2009
Time: 13:44



Search





Poll
Tech_Bl0G Quality?






[ Results | Polls ]
Votes: 3 | Comments: 0

Users
People on-line:     
guests 3 guests

Stats
Visits: 2829
Statistics

Admin Login

: