What causes a System.Runtime.InteropServices.COMException at BackgroundAudioPlayer.get_Position()?

2

Sometimes I'm getting an exception when trying to get the position of the BackgroundAudioPlayer.Instance. It's happening very rarely, but I've been able to get a StackTrace. The strange thing is, this code is executed every second while playing a track. What could be the cause of this error?

I'm getting this 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)

Of course the code I'm using is just plain simple.

public void UpdateTrackPosition()
{
    if (_backgroundAudioPlayer != null && _backgroundAudioPlayer.Track != null)
    {
        Position = _backgroundAudioPlayer.Position;
    }
    else
    {
        Position = null;
    }
}
c#
windows-phone-8
background-audio
asked on Stack Overflow Jul 9, 2013 by Mark Monster

1 Answer

3

That code is linked to MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED but I'm guessing that you do have sound.

I have found that the BackgroundAudioPlyer can be very weird. I wrap most of my calls with a "Safe" extension method.

Example

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

}
answered on Stack Overflow Jul 17, 2013 by Shawn Kendrot

User contributions licensed under CC BY-SA 3.0