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 上。:)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步