Use the MediaElement cause the error “The background audio resources are no longer available.”

纵饮孤独 提交于 2019-12-04 06:56:41

问题


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 ???


回答1:


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



来源:https://stackoverflow.com/questions/25992470/use-the-mediaelement-cause-the-error-the-background-audio-resources-are-no-long

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!