Im using MediaElement to play video and BackgroundAudioPlayer to play sound.
Here is an example.
I play remote sound through BackgroundAudioPlayer. Then I want to play the video before MediaElement starts playing the video Im calling BackgroundAudioPlayer.Close, as suggested in the best examples of BackgroundAudioPlayer.
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 playing the video, I want to play the sound 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();
Im getting an InvalidOperationException in the first line of code saying, "Background audio resources are no longer available." So, how can I reuse BackgroundAudioPlayer in my application after using MediaElement?
EDIT:
If you use MediaPlayerLauncher instead of MediaElement, it works during second time playback, because the application starts when MediaPlayerLauncher starts. But is it possible to mix MediaElement and BackgroundAudioPlayer in one application!?!?! This seems to be another nightmare from MS :(
source share