使用 MediaElement 会导致错误“背景音频资源不再可用". [英] Use the MediaElement cause the error "The background audio resources are no longer available."

查看:25
本文介绍了使用 MediaElement 会导致错误“背景音频资源不再可用".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我必须使用 AudioPlaybackAgent (APA) 和 mediaelement.我用APA播放歌曲,当我需要播放视频时,我使用MediaElement

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

当我使用 MediaElement 导航到一个页面时,我停止了 BackgroundAudioPlayer:

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

BackgroundAudioPlayer.Instance.Pause();

当我导航回到需要播放音乐的页面时,我调用 APA 重新开始,但现在它返回异常背景音频资源不再可用".:(

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();
        }
    }

我可以使用 MediaPlayerLauncher ,但是这个解决方案有很多缺点(只有全屏,缺少我的自定义控件......).那么有什么方法可以让媒体元素与 AudioPlaybackAgent 一起工作,或者以任何其他方式播放视频???

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

推荐答案

出现这种情况是因为在页面之间导航时数据丢失.您可以尝试将数据保存到IsolatedStorage.您可以在此问题中找到更多信息:在 Windows Phone 中的页面导航之间保存值

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

这篇关于使用 MediaElement 会导致错误“背景音频资源不再可用".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆