This project has moved and is read-only. For the latest updates, please go here.

Play audio in background

Jun 10, 2014 at 8:48 AM
Edited Jun 10, 2014 at 8:48 AM
Hello,

First of all, thank you very much for this excellent library !

I'm trying to play audio in background using AudioCategory="BackgroundCapableMedia" in MediaElement. It works well few seconds but after that, it freezes. If I go back to the application, the video is stuck.
Is there something I can do to make it work ?


Cordially,
Stephane.
Coordinator
Jun 10, 2014 at 11:56 AM
You're welcome.

Which version of the code are you using? Just after phonesm-1.2.2, 306effb31b16 set the background flag, but I don't recall actually testing it beyond putting the app in the background for a few seconds.

Are you seeing any errors or other oddities in the Output window (VS' Debug -> Windows -> Output)? For that matter, anything different in the log between when it is run in the foreground and in the background?
Jun 11, 2014 at 8:35 AM
I use the current source code. I looked at the output window but there is nothing special, no difference whatsoever launched in foreground or background.
I will try to debug it to see what's happen exactly.
Coordinator
Jun 14, 2014 at 1:40 AM
Any luck?
Jun 14, 2014 at 11:28 PM
In fact, there is a difference in the log. When it's launched in background, I don't know why, there is some 'BufferingManager.ReportExhaustion();' messages and a lot of buffering messages.
Coordinator
Jun 19, 2014 at 1:30 AM
It's as if something is slowing down or stopping the data getting to the MediaElement. Perhaps some status notification gets wedged (I think there would also need to be a blocking notification while a lock is being held, which should never be happening).
Almost all the processing for the media samples happens on the thread pool (mostly through "await XyzAsync().ConfigureAwait()" calls). Does anyone know if anything happens to the thread pool when a media-playing WinRT app goes into the background?
Aug 1, 2014 at 2:30 PM
Hi, we are experiencing the same issues with our app and the example apps. Both seem to stop playing after a certain amount of time. Probably when the buffer is empty. I see ReportExhaustion() in the output window as well and some buffering, but it doesn't seem like the buffer is filling up again.
Coordinator
Aug 1, 2014 at 9:24 PM
Something is definitely wrong. I'm looking at the output window while debugging NASA TV playing in the HlsView.WIn81 app. For a few seconds, the audio plays in the background. After that (maybe 20s?), the reader is still reading segments and both audio and video packets are being consumed. ...but the playback is stopped.. A little while later, the MediaElement stops consuming audio and video packets.

I think I need to do a careful read-through of the WinRT background audio documentation. Something is missing...