I’m using MediaElement for playing videos and BackgroundAudioPlayer for playing audio.
Here is a case.
I’m playing remote audio via BackgroundAudioPlayer. Then I want to play video and before MediaElement begins playing video I’m calling BackgroundAudioPlayer.Close as suggested in BackgroundAudioPlayer best practices.
MediaElement and the BackgroundAudioPlayer
Care must be taken when mixing BackgroundAudioPlayer and MediaElement for audio playback.
1. Close() must be called before switching to MediaElement playback.
2. There is only one media queue. Your application cannot pause background audio, play something with MediaElement then resume the background audio stream.
But after video is playing I want to play audio again.
// Play audio result
BackgroundAudioPlayer.Instance.Track = new AudioTrack(new Uri(audioSearchResult.Url, UriKind.Absolute), audioSearchResult.Title, null, null, null,
AudioPlayer.TrackStateBuffering, EnabledPlayerControls.All);
BackgroundAudioPlayer.Instance.Play();
I’m getting InvalidOperationException
on first line of code saying “The background audio resources are no longer available”.
So how can I reuse BackgroundAudioPlayer in my app after using MediaElement?
EDIT:
If use MediaPlayerLauncher instead of MediaElement it works second time audio being played cause app is being tombstoned when MediaPlayerLauncher launches. But is it possible to mix MediaElement and BackgroundAudioPlayer in one app!?!?! Seems to be another nightmare from MS:(