locked
App gets suspended while playing audio in background when in connected standby...

    Question

  • My App plays videos in playlist mode. when video ends, app set media source to next video in the list.

    I have added BackgroundCapableMedia audio category, added audio task declaration and registered for media transport controls. when app goes into background, it continue playing music. I have tested it playing at least 20 videos while in background.

    When machine (Surface RT) goes into Connected Standby, audio keeps playing fine but for few videos and then audio stops. After adding logs, I figured out that app is getting suspended after sometime when in CS. Usually I see suspend log entry just after media loaded event (but I have seen it after media started too).

    One reason I can think is app is not playing audio (may be because its loading new video) and that why it gets suspended. How can I prevent app to go into suspended state? I thought adding background audio task should prevent app going into suspend state. here is the closest thing I have found so far:

    From:http://blogs.msdn.com/b/windowsappdev/archive/2012/05/16/being-productive-when-your-app-is-offscreen.aspx

    "Your app can now play audio in the background without being suspended. But because playing audio in the background leaves the app active, you have a responsibility to ensure that your app doesn’t eat up system performance or battery life. As soon as your app stops playing audio, Windows will suspend it. "

    Wednesday, May 1, 2013 1:56 AM

Answers

  • Hello Jeff,

    Yes using two players is the recommended approach. This will give you more control over when and how the transition between you content starts. You can even do cool cross fade effects with this approach.

    Let me take a look at the other thread that you mention. I'll follow up in the context of that thread.

    Thanks,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, May 2, 2013 11:29 PM
    Moderator

All replies

  • I just started my app and put machine into CS. it played 8 videos for around 40 minutes before app was suspended (app suspended just after media Started event).
    Wednesday, May 1, 2013 2:43 AM
  • Hi,

    I'll try to involve more experts in this case.


    Aaron
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 2, 2013 9:33 AM
  • Hello,

    Please insure that you are using two separate media element instances and pre-rolling one of the instances before the first instance ends. you might want to try starting playback of the second instance just before playback of the first instance stops. You should be able to do this via the duration and the current position.

    Reference: http://msdn.microsoft.com/en-us/library/windows/apps/hh452805.aspx

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, May 2, 2013 5:20 PM
    Moderator
  • is this recommended approach? I have looked at pretty much all documentation on background audio playback and none of them have mentioned this :(. I have to change few things in my code to adapt this. I will give a try. thanks! BTW another bug is preventing me to use mediaended event :(

    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/4af53ba0-906d-4f99-9d70-a91ed7a27c0b/

    Also link you pointed have JS example. C# article doesn't even mention smooth transition :). 
    • Edited by JeffCar123 Thursday, May 2, 2013 10:11 PM
    Thursday, May 2, 2013 10:08 PM
  • Hello Jeff,

    Yes using two players is the recommended approach. This will give you more control over when and how the transition between you content starts. You can even do cool cross fade effects with this approach.

    Let me take a look at the other thread that you mention. I'll follow up in the context of that thread.

    Thanks,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, May 2, 2013 11:29 PM
    Moderator
  • One more weird thing is, media transport controls are still visible when volume button press even though app is suspended. interacting with media transport control at this stage crashes app. 
    Thursday, May 2, 2013 11:46 PM
  • is there a C# example for this :) ?
    Friday, May 3, 2013 7:30 PM
  • James,

    Using two MediaElements should not be required, as this is not a trivial thing to implement.

    While there are benefits to pre-loading the next track, having to manage multiple MediaElements becomes very difficult. It's not just that you have to preload the next track in the other MediaElement and start playback, but there are many other MediaElement events that can occur or other async activities like seeking or jumping to another track position. Also, we may not immediately have the next track available, as some "playlists" are generated dynamically, and the next track is not known until after the first track starts playing. This sets up the potential for many bugs and race conditions in our app.

    Furthermore, we currently are using the same code for audio playback across Windows 8/RT, Windows desktop (WPF), and Xbox apps. It is not clear that we can instantiate more than one MediaElement on all of the these platforms, or we have to maintain more complex code to deal with different capabilities between platforms.

    It would be far better to provide support in MediaElement for a second source, or to provide an object that encapsulates two MediaElements and provides the automatic switching. This would more easily allow "gapless playback" of audio or video tracks.

    In the meantime, I hope that you can just fix the Connected Standby race condition so that the app doesn't get suspended if the next track starts soon after the current track ends.

    Adam Krantz
    Senior Technical Lead
    Rhapsody International

    Friday, July 5, 2013 6:56 PM
  • Hello Adam,

    Have you tried to reproduce the issue on Windows 8.1?

    Thanks,

    James

    Tuesday, July 9, 2013 12:45 AM
  • The issue is alive and well in Windows 8.1 :-(

    http://social.msdn.microsoft.com/Forums/windowsapps/en-US/a90fcc68-6cbf-4991-9e38-6f43563f10e4/background-audio-during-connected-standby?forum=winappswithcsharp

    Monday, December 2, 2013 9:50 AM