i have this little piece of C# code
//Creates a MediaPlayer with the sound you want to play
public static void PlaySound (Stream wavStream, string wavName, bool loop)
{
//Get the path for the file to play
var path = GetFilePath(wavStream, wavName);
var player = new MediaPlayer();
player.Open(new Uri(path));
player.MediaEnded += loop ? new EventHandler(MediaEndedLoop) : new EventHandler(MediaEndedDestroy);
player.Play();
players.Add(player);
names.Add(wavName);
}
I dont know why but MediaEndedLoop and MediaEndedDestroy are never called
Any idea?
The
MediaPlayer
requires aDispatcher
in order to dispatch theMediaEnded
,MediaOpened
... events.When you are using a WinForm application a
Dispatcher
should already have been registered. That means that you should not have to do anything to get the events working.If you want to receive events in a console application you'll have to run the
Dispatcher
yourself.I also had this problem. I couldn't find a solution, but I did come up with a workaround if your media exists in a looping application or thread. You can just manually reset the position after a certain point.
That's the best I can offer as of now.