开发者

Media player in Windows Phone 7

开发者 https://www.devze.com 2023-03-22 18:57 出处:网络
I am using the media player in Windows Phone 7 to play the music in the phone song collection. But when it play the music they will be an exception and the error is stating

I am using the media player in Windows Phone 7 to play the music in the phone song collection. But when it play the music they will be an exception and the error is stating

FrameworkDispatcher.Update has not been called. Regular FrameworkDispatcher.Update calls are necessary for fire and forget sound effects and framework events to function correctly.

How should i go about modifying my code?

private void songBtn_Click(object sender, RoutedEventArgs e)
{
    using (var ml = new MediaLibrary())
    {
        foreach (var song in ml.Songs)
        {
            System.Diagnostics.Debug.WriteLine(song.Artist + " " + song.Name);
            MessageBox.Show(song.Artist + " " + song.Name);
       开发者_运维知识库 }
        MediaPlayer.Play(ml.Songs[0]);
    }
}


You have to call

FrameworkDispatcher.Update()

whenever you make a call to an XNA media library so your code should look like this

using (var ml = new MediaLibrary())
{

  foreach (var song in ml.Songs)
  {
      System.Diagnostics.Debug.WriteLine(song.Artist + " " + song.Name);
      MessageBox.Show(song.Artist + " " + song.Name);

  }
  FrameworkDispatcher.Update();
  MediaPlayer.Play(ml.Songs[0]);
}


The error is occouring because you're using the XNA Framework in a regular Windows Phone 7 application.

If you read the error description, you would gotten this link to MSDN: Enable XNA Framework Events in Windows Phone Applications , which explains precisely what to do.

0

精彩评论

暂无评论...
验证码 换一张
取 消