I transfer music from the Internet to the background agent using my own MediaStreamSource. Under good network conditions, this works fine, but when the network connection is spotty, a strange problem arises.
When the track starts playing, everything goes up the first call to MediaStreamSource.GetSampleAsync (). Since the connection is spotty, if insufficient data is available, the source calls ReportGetSampleProgress (double) and returns without a sample message. This is consistent with the MSDN documentation and sample code.
Curiously, there are no more GetSampleAsync calls anymore! As buffering continues, the source continues to ReportGetSampleProgress until the sample is ready when it calls ReportGetSampleProgress(1.0) to indicate the full buffer.
I tried several approaches, including:
ReportGetSampleCompleted when buffering is complete; this is because load events occur in arbitrary threads, and this method is explicitly sensitive to both the calling thread and the call to GetSampleAsync on the stack; invalid call circumstances result in COM errors.- In accurate error mode, stop and start BackgroundAudioPlayer: this does not allow restarting streaming.
How can I get streaming playback again as soon as the initial failure to read the sample hangs things?
source share