I have an app for WP7, using BackgroundAudioPlayer as we need to play in the background. The problem is, when there’s already an app playing audio in the background, I can’t get my AudioPlaybackAgent work, the previous music just keep playing.
The document introduced this way,
BackgroundAudioPlayer.Instance.Close();
by which I can only close the audio that is played by myself or Zune, but it doesn’t work when the audio is played by other apps.
So is there a way to close all the playing audio?
OK I fixed it.
What I did to get it play is like this, first I set a track to the player:
Then an
OnPlayStateChangedevent will fire in the background agent, where I call theBackgroundAudioPlayer.Instance.Play()method. This seems to work great.But if the background player is already being used by another app, the
PlayStatewon’t change toTrackReadywhen I set the track, and consequently the event won’t fire.To fix this, I simply call the
.Play()method in the main UI thread, right after setting the track. And it works.