我正在尝试在我的一个应用程序中获得一个警告声音,以便播放Zune中正在播放的任何内容。我正在使用BackgroundAudioPlayer播放我的声音。
现在,当我的警告声音播放时,它会停止当前的Zune歌曲。有没有办法暂停Zune曲目,播放警告声音,然后恢复Zune声音?
我已经看过了音频是如何工作的,所以我认为这是不可能的,只有一个媒体播放器,所有的元素都放在一个队列中……但我很乐意找到一种变通办法。
发布于 2011-11-16 13:15:21
这里有一个示例:http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx
示例正在执行此操作(请注意,您需要引用XNA并初始化GameTimer对象以使用MediaPlayer类):
public MainPage()
{
InitializeComponent();
// Timer to simulate the XNA game loop (SoundEffect class is from the XNA Framework)
GameTimer gameTimer = new GameTimer();
gameTimer.UpdateInterval = TimeSpan.FromMilliseconds(33);
// Call FrameworkDispatcher.Update to update the XNA Framework internals.
gameTimer.Update += delegate { try { FrameworkDispatcher.Update(); } catch { } };
// Start the GameTimer running.
gameTimer.Start();
// Prime the pump or we'll get an exception.
FrameworkDispatcher.Update();
}
// Flag that indicates if we need to resume Zune playback upon exiting.
bool resumeMediaPlayerAfterDone = false;
private void ZunePause()
{
// Please see the MainPage() constructor above where the GameTimer object is created.
// This enables the use of the XNA framework MediaPlayer class by pumping the XNA FrameworkDispatcher.
// Pause the Zune player if it is already playing music.
if (!MediaPlayer.GameHasControl)
{
MediaPlayer.Pause();
resumeMediaPlayerAfterDone = true;
}
}
private void ZuneResume()
{
// If Zune was playing music, resume playback
if (resumeMediaPlayerAfterDone)
{
MediaPlayer.Resume();
}
}发布于 2011-11-16 18:34:08
正如你所假设的,你不可能暂停正在Zune中播放的任何东西,通过BackgroundAudioPlayer播放一首曲目/声音,然后在Zune中恢复之前播放的曲目。
BackgroundAudioPlayer使用与Zune播放器相同的媒体队列,所以当你的曲目被BAP播放时,以前在队列中的任何东西都会被删除。即使不是,也不可能从BAP播放(或触发播放)来自MediaLibrary的曲目。
在这里,使用背景音频似乎是完全错误的选择。(或者你有必须使用它的理由吗?)
为什么不在用户已经在播放的任何音频之上播放通知声音呢?(使用MediaElement或SoundEffect。)我假设这个警告通知噪音只是一个简短的错误蜂鸣声,所以这首曲子在其他音乐之上应该不会有任何问题。您可以将音频通知与VibrateController的使用相结合,以帮助用户清楚地知道出了什么问题。
或者,由于通知是在应用程序运行时发出的,为什么不使用警告的可视指示?
https://stackoverflow.com/questions/8145948
复制相似问题