Reputation: 11
I'm trying to get a warning sound in one of my apps to play over whatever is playing in Zune. I am using a BackgroundAudioPlayer
to play my sound.
Right now when my warning sound plays it stops the current Zune song. Is there any way to pause the Zune track, play the warning sound, and then resume the Zune sound?
I already took a look at how the audio works so I don't think this is possible, there is only 1 media player and all elements are placed in a queue... But I would love to find a workaround.
Upvotes: 1
Views: 929
Reputation: 65556
As you assume, it's not possible to pause whatever is playing in Zune, play a track/sound via the BackgroundAudioPlayer and then resume the previously playign track in Zune.
The BackgroundAudioPlayer uses the same media queue as the Zune player so when your track is played by the BAP whatever was previusly in the queue is removed. Even if it wasn't it's not possible to play (or trigger the playing of) a track from the MediaLibrary from the BAP.
Use of background audio seems completely the wrong option here. (Or do you have a reason you must use it?)
Why not play your notification sound over the top of any audio the user is already playing? (Using either a MediaElement or SoundEffect.) I'd assume this warning notification noise is just a short error beep so there shouldn't be any issue with this palyign over the top of any other music. You could combine your audio notification with use of the VibrateController to also help make it clear to the user that something is wrong.
Alternatively, as the notification is while your app is running, why not use a visual indication of the warning?
Upvotes: 0
Reputation: 31724
There is a sample here: http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx
The sample is doing this (note you need to reference XNA and initialize the GameTimer object to use the MediaPlayer class):
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();
}
}
Upvotes: 1