gpt4 book ai didi

c# - 是什么导致 BackgroundAudioPlayer.get_Position() 出现 System.Runtime.InteropServices.COMException?

转载 作者:行者123 更新时间:2023-11-30 22:16:14 24 4
gpt4 key购买 nike

有时我在尝试获取 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;
}
}

最佳答案

该代码链接到 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;

}

关于c# - 是什么导致 BackgroundAudioPlayer.get_Position() 出现 System.Runtime.InteropServices.COMException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17541615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com