Hello How to create a List<SystemSound> with music from recourses?
I try this, but i get below exception:
List<System.Media.SystemSound> music = new List<System.Media.SystemSound>
{
global::Launcher.Properties.Resources.music_quit_1,
global::Launcher.Properties.Resources.music_quit_2,
global::Launcher.Properties.Resources.music_quit_3,
global::Launcher.Properties.Resources.music_quit_4,
};
“Argument 1: Can not convert from System.IO.UnmanagedMemoryStream to
System.Media.SystemSound.”
From that I will random on music and after play it.
The class
System.Media.SystemSoundis not used this way, this class is only used to represent a system sound type such asAsterisk,Beep,Hand,QuestionorExclamation. A system sound can be played throughSystemSounds.Example
This example will play the system sound
Asterisk. This is similar toSystem.Drawing.Brushas you can not saySystem.Drawing.Brush.Blackbut you can saySystem.Drawing.Brushes.Black.System.Drawing.Brushwas only used to define an object of nameBlackin a new class of nameSystem.Drawing.Brushesas a colorBlack. We can see this in the definition ofSystem.Drawing.BrushesMoreover, if you would like to play a new Wave Sound, you may create a new class of
SoundPlayerwhich controls playback of a sound from a Sound Wave(.wav) fileExample
If you still would like to use a Generic
List. Then, perhaps the following example may help youExample
Notice:
SoundPlayeris only used to play Wave Sound files. If you would like to play other media files such as .mp3, .mpeg, etc… Then, you may useSystem.Windows.Media.MediaPlayerwhich can be imported from theObject Browserto create a new class ofMediaPlayerand play a particular file.Example
IMPORTANT: To use
MediaPlayer, you have to add a new reference ofWindowsBase.To add a new reference of
WindowsBase, try the following:Make sure that the new reference you’ve just added has its property of bool of name Copy Local set to True so that the client won’t encounter errors during initialization
Thanks,
I hope you find this helpful 🙂