0

In my app, I have to use an AudioPlaybackAgent (APA) and a mediaelement. I used the APA to play songs , and when I need to play video, I use the MediaElement

When I navigate to a page use the MediaElement, I stop the BackgroundAudioPlayer:

BackgroundAudioPlayer.Instance.Pause();

When I navigate back to a page which need to play music, I call the APA to start again, but now it return the exception "The background audio resources are no longer available." :(

protected override void OnNavigatedTo(NavigationEventArgs e)
    {            
        base.OnNavigatedTo(e);

        try
        {
            if (BackgroundAudioPlayer.Instance.PlayerState != PlayState.Playing)
                BackgroundAudioPlayer.Instance.Play();                
        }
        catch
        {
             BackgroundAudioPlayer.Instance.Play();
        }
    }

I can use the MediaPlayerLauncher , but this solution has many disvantage (only fullscreen, lack of my custom control ...). So is there any way to make the media element work along with the AudioPlaybackAgent, or any other way to playing video ???

user3448806
  • 897
  • 10
  • 22
  • Are you making sure that when you stop the BackgroundAudioPlayer the code on the BackgroundAudioPlayer hits the `NotifyComplete()` at some point? The BackgroundAudioPlayer can be very tricky sometimes and I think I ran into that problem too. I don't think it is related to page navigation either. If you have any doubts about this comment let me know. – meneses.pt Sep 24 '14 at 09:30

1 Answers1

0

This occurs because data get lost when navigating between pages. You can try saving data to IsolatedStorage. You can find more information in this question: Save values between page navigation in Windows Phone

n32303
  • 831
  • 1
  • 10
  • 25
  • I don't think because of lost data when navigating, my data (links of song) of my background music saved in Isolated storage, and it call automatic. But when I closed it to play my Media Element, I can't get it back ( if I closed it when I deactived app and then actived app again, it worked fine ) – user3448806 Sep 24 '14 at 02:06