How to detect if another audio is playing in background? (Windows Phone 7)

你说的曾经没有我的故事 提交于 2019-11-26 21:49:20

问题


One of my apps have recently failed certification because: "my app stops background music without asking user when it wants to play some music".

Now the question is: how can we detect if there is any music playing in the background?

Regards


回答1:


  using Microsoft.Xna.Framework.Media;

...

    if (Microsoft.Xna.Framework.Media.MediaPlayer.State == MediaState.Playing)
    {
          ....
    }



回答2:


You need to examine the MediaPlayer.GameHasControl property.

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.mediaplayer.gamehascontrol.aspx

MediaPlayer.State will be Playing even if you're playing the music. GameHasControl determines if the music was started from your app, or if another app was playing before your app started.

You can get the value in OnActivated...

protected override void OnActivated(object sender, EventArgs args)
{
  base.OnActivated(sender, args);


  // cache music and trial mode values
  Globals.GameHasMusicControl = MediaPlayer.GameHasControl;

}

And use that value throughout your game to determine whether or not you should play music.



来源:https://stackoverflow.com/questions/7034205/how-to-detect-if-another-audio-is-playing-in-background-windows-phone-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!