I need to store background audio play position in case another application gets started and takes over background audio player facility.
I have used the following in my audio player agent
protected override void OnPlayStateChanged(BackgroundAudioPlayer _player, AudioTrack _track, PlayState _playState)
{
System.Diagnostics.Debug.WriteLine(_playState.ToString());
double _pos = -1;
try
{
_pos = _player.Position.TotalSeconds;
}
catch (Exception _ex)
{
System.Diagnostics.Debug.WriteLine(_ex.Message);
}
switch (_playState)
{
// handling of different state changes
}
myStorePositionRoutine(_pos)
NotifyComplete();
}
Other state changes coming from e.g. buffering or play / pause etc events seem to work fine and I am able to get the latest position recorded for possible later use.
However, if and when (while running my app in debugger) I start another application which takes over the background audio player facility in the phone, the first (and last) event in debugger I can see is play state
"Stopped"
and the exception message
"The background audio resources are no longer available."
Is there something I could do to force the background audio player agent make regular position saves in anticipation of a "non graceful" shut down - or is there some other way / event to use get and store the position preceding that stopped status and unavailability of background audio resources?