Search code examples
c#windows-phone-7eventswindows-phone-8media-player

MediaPlayer.MediaStateChanged & MediaPlayer.ActiveSongChanged events don't seem to trigger


In the PhoneApplicationLoaded event I added the following code:

MediaPlayer.MediaStateChanged += StateSongChanged;
MediaPlayer.ActiveSongChanged += StateSongChanged;

But the StateSongChanged procedure doesn't seem to tigger?

Does anyone know why this is, I'm fairly new to C# so it's probably something fairly simple.

In addition, this is the StateSongChanged block:

private void StateSongChanged(object sender, EventArgs e)
{
    // Code
}

Solution

  • XNA Framework events are triggered after calling

    FrameworkDispatcher.Update();
    

    so it's convenient to create IApplicationService class with timer, that calls FrameworkDispatcher.Update() over and over again.

    For more info and how to read this: Enable XNA Framework Events in Windows Phone Applications