windows phone 7 后台音乐播放功能,出错。

hdingmin 2012-12-03 04:59:01
我是用silverlight写的程序,后台播放音乐用的是
  2、Song+MediaPlayer

  优点:小巧轻便,简单易用,支持格式多,可直接从Uri中加载。

  缺点:需启用XNA Framework。

  适用场合:后台播放完整音频。

  相关代码:

song = Song.FromUri("music", new Uri("badapple.mp3", UriKind.Relative));MediaPlayer.Play(song);
这个代码,但是程序能正常播放音乐。只是vs会报错。于是我百度了解决方案
就是这个方案
Solution

Event based systems place messages in a message queue and keep it for dispatching. XNA framework messages also follows it and places them in a queue which will be processed by the XNA framework. If you come across such exception detailed above, you have to call the FrameworkDispatcher.Update() method once per frame in a timer loop. You can also implement the IApplicationService interface and use the timer Tick event.



Here is the sample implementation code for IApplicationService to update the FrameworkDispatcher:

public class DispatcherService : IApplicationService
{
private DispatcherTimer m_dispatcherTimer;

public DispatcherService()
{
m_dispatcherTimer = new DispatcherTimer();
m_dispatcherTimer.Interval = TimeSpan.FromTicks(10000);
m_dispatcherTimer.Tick += frameworkDispatcherTimer_Tick;
FrameworkDispatcher.Update();
}

void frameworkDispatcherTimer_Tick(object sender, EventArgs e)
{
FrameworkDispatcher.Update();
}

void IApplicationService.StartService(ApplicationServiceContext context)
{
m_dispatcherTimer.Start();
}
void IApplicationService.StopService()
{
m_dispatcherTimer.Stop();
}
}


Now, you need to register this service in your application class (either XAML or Code behind). Here is the XAML code that you need to add in your App.xaml file:


<Application.ApplicationLifetimeObjects>
<service:DispatcherService />
</Application.ApplicationLifetimeObjects>

上面这个solution看不懂,翻译过来还是没看懂。希望知道为什么会出现这个问题以及为什么要用这个代码解决的大侠能给我说说。谢谢。本人学生不懂的地方太多。。。。.
...全文
199 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hdingmin 2012-12-04
  • 打赏
  • 举报
回复
没人回答吗。

7,655

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧