问题描述
大约一周前,我为 Windows Phone 商店提交了一个在线后台广播流应用程序.该应用程序非常好(因为我使用模拟器测试它,它在所有可能的领域都很好)但是当我提交它进行认证时,它失败了.
around a week ago, I submitted an online Background Radio Streaming app for the Windows Phone store. The app was quite good (as I used the Emulator to test it, it was good on all the possible sectors) but when I submitted it for certification, it failed.
根据错误日志,如果有人已经从音乐 + 视频中心播放音乐,然后尝试打开此应用程序,这两个应用程序都会意外崩溃并停止.
According the the error log, if someone is already playing a Music from Music + Video hub and then tries to open this app, both of the apps Crash and stop unexpectedly.
到目前为止我明白,这是因为音乐+视频中心的音乐也是背景音乐,同时播放2个背景音乐,应用程序崩溃.这可能是其他一些原因,但所描述的原因对我来说似乎更合乎逻辑.
So far I understood, it is because the Music of Music + Video hub is also Background Music and for playing 2 Background Musics at the same time, the apps are Crashing. It can be some other reason but the described one seemed more logical to me.
那么,谁能告诉我如何更改音乐+视频中心的应用程序状态?我想暂时暂停或停止音乐 + 视频中心的应用程序,以便应用程序的两个状态不相同.这样,应用程序不会在后台相互冲突.
So, is there anyone who can tell me how to change the state of the app of Music + Video hub? I want to pause or stop the app of Music + Video hub for the time being so that both of the states of the app are not same. In that way, the apps won't clash with each other in the background.
有人能帮我解决这方面的问题吗?
Can anyone help me in this regard?
推荐答案
使用gameHasControl检查其他使用音乐的BAP:
Use gameHasControl to check for other BAP using music:
bool gameHasControl = Microsoft.Xna.Framework.Media.MediaPlayer.GameHasControl;
if (!gameHasControl)
{
MessageBox.Show("stopping other player"); // normally you should ask if to do that
BackgroundAudioPlayer.Instance.Stop();
}
一旦它停止,当你启动你的 BAP 时,旧实例调用 Shutdown(),你的 BAP 将是新实例,你可以正常使用.当您的 BAP 在内存中并且您从音乐+视频中心开始播放时也是如此.
只需要当心,因为当你使用 XNA 时,你有时需要这样做:
Once it is Stopped, when you start your BAP, then old instance invokes Shutdown(), and your BAP will be new Instance, which you can normally use. The same is when your BAP is in memory and you start to play from Music+Video Hub.
Only watch out, because when you use XNA, you sometimes need to do:
FrameworkDispatcher.Update();
否则您的应用有时会崩溃.祝你好运.
编辑 - 评论后
要使其工作,您需要添加对 Microsoft.Phone.BackgroundAudio 的引用或像这样使用:
Otherwise your App will sometimes crash. Good luck.
EDIT - after comment
To make it work you need to add a reference to Microsoft.Phone.BackgroundAudio or use like this:
Microsoft.Phone.BackgroundAudio.BackgroundAudioPlayer.Instance.Stop();
BackgroundAudioPlayer 是您可以使用的 Singleton
- 在这种情况下 - 停止播放(当然让用户选择).
BackgroundAudioPlayer is a Singleton
which you are allowed to use - in this case - Stop it playing (of course give the choice to the User).
这篇关于Windows Phone 8 - 2 背景音频冲突并且两个应用程序都终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!