Windows Phone 7 中的媒体播放器

发布于 2024-11-26 04:07:29 字数 601 浏览 0 评论 0原文

我正在使用 Windows Phone 7 中的媒体播放器来播放手机歌曲集中的音乐。但是当它播放音乐时,它们将是一个例外,并且错误指出

FrameworkDispatcher.Update 尚未被调用。定期调用 FrameworkDispatcher.Update 是“即发即忘”音效和框架事件正常运行所必需的。

我应该如何修改我的代码?

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]);
    }
}

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]);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

春夜浅 2024-12-03 04:07:29

必须拨打

FrameworkDispatcher.Update()

每当您拨打 XNA 媒体库时都
所以你的代码应该是这样的

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]);
}

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]);
}
自由如风 2024-12-03 04:07:29

发生该错误的原因是您在常规 Windows Phone 7 应用程序中使用 XNA Framework。

如果您阅读错误描述,您将获得 MSDN 链接:在 Windows Phone 中启用 XNA Framework 事件应用程序,它准确地解释了要做什么。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文