XNA游戏 上传到MarketPlace 失败原因之一--------游戏背景音乐与手机本身音乐冲突...

本文介绍了一款XNA游戏在Windows Phone 7平台上遇到的背景音乐与手机音乐冲突问题及解决方案。通过检测手机音乐状态并请求用户许可,确保了良好的用户体验。

    前些天自己做了一个在windows phone 7上的 XNA 游戏,完成之后上传到 微软的 MarketPlace 上后,过了两天看到自己在 MarketPlace 上的操作面板提示认证失败,下载文档后,看到以下部分摘要:

Requirements

When the user is already playing music on the phone when the application is launched, the application must not pause, resume, or stop the active music in the phone MediaQueue by calling the Microsoft.Xna.Framework.Media.MediaPlayer class. If the application plays its own background music or adjusts background music volume, it must ask the user for consent to stop playing/adjust the background music (e.g. message dialog or settings menu). This prompt must occur each time the application launches, unless there is an opt-in setting provided to the user and the user has used this setting to opt-in.

   Expected Result 

     Test Process Required: 1. Play a music file. 2. Launch the application. 3. Verify that while the application loads, it does not pause, resume or stop the actively playing music.

Comments: The application does not have settings that allow the user to configure the application's background music.

   才知道,自己游戏的 背景音乐可能会跟用户手机正在播放的音乐有冲突,所以为了更好的用户体验,程序员自己必须得解决这个很容易发生的冲突。我想了几个解决方法,最重选择了一个简单的方法:在游戏运行起来时,检测用户手机的音乐是否正在工作,在你的Game 类对象 或者 组件类对象(继承自DrawableGameComponent) 对象中加上:

      

        bool shouldTheBackgroundMusicPlay=true;

         //背景音乐         

        SoundEffect BackgroundSound;   

       public static  SoundEffectInstance BackgroudSoundInstance;

      void  IsCurrentDeviceMediaQueueNull()

   {           

               if (Microsoft.Xna.Framework.Media.MediaPlayer.Queue.Count > 0)       

              {                

                     shouldTheBackgroundMusicPlay = false;      

               }          

     } 

    Game 类对象 或者 组件类对象  的 Initialize() 方法中加入以下代码,用来提示用户当前音乐如果在播放,则游戏背景音乐不会播放,如果想播放游戏背景音乐,必须得先暂停本机其它正在工作的媒体播放器:

    //检测当前用户的 Media 是否在工作  如果在工作则弹出对话框            

       if (Microsoft.Xna.Framework.Media.MediaPlayer.Queue.Count > 0)     

        {                

                   MessageBox.Show("Your Device's Media is working now,and the game'background music won't play,if you want to play the game'background music,please stop the device Media first.");      

       }  

    然后在 Game 类对象 或者 组件类对象的 Update() 方法中加入以下代码:

 if (shouldTheBackgroundMusicPlay)                

  {                    

              BackgroudSoundInstance.Play();  //播放背景音乐          

  }

   在 模拟器上和真机上都运行正常,OK,马上上传到 MarketPlace 上。:)

转载于:https://www.cnblogs.com/hebeiDGL/archive/2011/11/09/2241951.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值