zoukankan      html  css  js  c++  java
  • XNA游戏 上传到MarketPlace 失败原因之一游戏背景音乐与手机本身音乐冲突

        前些天自己做了一个在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 上。:)

  • 相关阅读:
    解决Enterprise Library January 2006不能加密配置文件的方法
    ASP.NET Ajax 和ASP.NET 2.0 的登陆控件相冲突的问题的讨论
    十二时辰与时间对照表,十二经络时辰表
    对表中数据逐行累加
    SQL脚本 CASE...WHEN...THEN...ELSE...END 的应用
    [转]看刚毕业MM如何在北京买房
    让你的GUI程序随WINDOWS服务一起启动
    启动Oracle,SQL服务,IIS脚本
    无论买新房还是二手房 教你六招可放心收房
    经典开源项目简介及源码下载
  • 原文地址:https://www.cnblogs.com/hebeiDGL/p/2241951.html
Copyright © 2011-2022 走看看