我在Windows Phone 7应用程序中使用BackgroundAudioPlayer
代理。跟踪结束时,代理端接收TrackEnded
事件,但UI端未接收任何事件。
另外,当我有意将音频轨道的位置设置为结尾时,然后调用Play()
,代理端将接收TrackEnded
事件(因为该轨道已结束),但是UI端会在其Stopped
处理程序中接收到PlayStateChanged
。太奇怪了 !
如何让UI知道轨道已经结束?通过隔离存储进行通信不是我的最爱!
最佳答案
通过研究和一些测试,使用隔离存储作为BackgroundAudioPlayer
的Background和Foreground实例之间的中间人,仍然是Windows Phone 7的唯一途径。这里提到了这些选项(我知道您知道)。 。
http://blogs.msdn.com/b/wpukcoe/archive/2012/02/10/background-audio-in-windows-phone-7-5-part-2.aspx
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202944(v=vs.105).aspx
https://stackoverflow.com/a/11419680/247257
彼得·托尔(Peter Torr)也证实了这一点:
For example, the agent may need to tell the foreground “I just started pre-downloading the next track,” or “I updated a database table and you should refresh your state”. Such notifications are impossible to create with Windows Phone OS 7.1; at best you can model them by using polling techniques, but this approach is inefficient and prone to errors.
唯一的好消息是,在同一篇文章中,他给出了Windows Phone 8的解决方案(使用IPC的命名事件),该解决方案更加可靠...
http://blogs.windows.com/windows_phone/b/wpdev/archive/2013/03/27/using-named-events-to-coordinate-foreground-apps-and-background-agents.aspx
关于windows-phone-7 - WP7如何检测音轨何时结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13618390/