2

有时我在尝试获取 BackgroundAudioPlayer.Instance 的位置时遇到异常。这种情况很少发生,但我已经能够获得 StackTrace。奇怪的是,这段代码在播放曲目时每秒都会执行一次。此错误的原因可能是什么?

我得到了这个 StackTrace。

System.SystemException: HRESULT = 0xC00D36C4 ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0xC00D36C4 at 
Microsoft.Phone.BackgroundAudio.Interop.IAudioPlaybackManager.get_CurrentPosition() at 
Microsoft.Phone.BackgroundAudio.BackgroundAudioPlayer.get_Position() --- End of inner exception stack trace --- at 
Microsoft.Phone.BackgroundAudio.BackgroundAudioPlayer.get_Position() at 
MC.PodCast.Common.ViewModel.PlayerViewModel.UpdateTrackPosition() at 
MC.PodCast.Common.ViewModel.PlayerViewModel.ReactToBackgroundAudioPlayer() at 
MC.PodCast.Common.ViewModel.PlayerViewModel.Initialize() at 
MC.PodCast.Common.ViewModel.PlayerViewModel.<<get_InitializeCommand>b__5>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)

当然,我使用的代码很简单。

public void UpdateTrackPosition()
{
    if (_backgroundAudioPlayer != null && _backgroundAudioPlayer.Track != null)
    {
        Position = _backgroundAudioPlayer.Position;
    }
    else
    {
        Position = null;
    }
}
4

1 回答 1

3

该代码链接到 MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED 但我猜你确实有声音。

我发现 BackgroundAudioPlyer 可能很奇怪。我用“安全”扩展方法来包装我的大部分通话。

例子

public static PlayState PlayerStateSafe(this BackgroundAudioPlayer source)
{
    PlayState state;
    try
    {
        state = source.PlayerState;
    }
    catch (InvalidOperationException)
    {
        state = PlayState.Unknown;
    }
    return state;

}
于 2013-07-17T13:44:24.103 回答