locked
After publishing, my background audio no longer works

    Question

  • Hi coders, i have a problem with an app i published. It´s my first app so its proberbly a beginner problem. Here goes :

    Its an interval trainer app. It´s supposed to run in the background when you bring it along for your workout. I tested it both in the emulater, and on my device.. It works as it is supposed to in either case. BUT if i pull the usb cable from my phone, and try and run the app, audio no longer works in the background, only in the foreground?? Same if i download the app (which i had to pull).

    Why is it behaving like that?? 

    Its a windows phone 8.1 project. I´m writing in c#, and the i use a runtime component to play the BackgroundMedia.

    I have registered the runtime component in the appmanifest.

    I hope someone can help me, because its really beyond me where the issue is. 


    • Edited by jrasbr Tuesday, April 28, 2015 8:44 PM
    Tuesday, April 28, 2015 6:10 PM

All replies

  • Hi jrasbr,

    >>i use a runtime component to play the BackgroundMedia.

    Which type of system trigger you are using? Why do you need to use a runtime component to play Background audio?

    You can have a look at the method in this article: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn642090.aspx

    Also check this sample: https://code.msdn.microsoft.com/windowsapps/BackgroundAudio-63bbc319

    As a suggestion, you can make a simple test: remove the runtime component and retest, check if the background task can work normally.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 29, 2015 6:50 AM
    Moderator
  • Hi Franklin.

    I´m not sure i know what you mean when you say system trigger? I use the runtime component, because as far as i can tell - thats whats being used in the test-sample from the link you posted - which also was the code i used in my solution.

     after reading the article, and searching the net for a solution, i stumpled across this a few times : 

    A background task can be terminated without warning under the following circumstances:

    -A resource policy is violated

    A resource policy is violated.. I´m using set uri source, and read somewhere that accessing folders from the background can be some kind of violation, but i have tried setting MediaPlayer.SetFileSource() - also with no luck.

    What really bugs me is that it works in the testinviroment, but not after release. 


    • Edited by jrasbr Wednesday, April 29, 2015 9:37 AM
    Wednesday, April 29, 2015 9:35 AM
  • Still no solution.. Anyone?

    Also i dont know how to debug it when error only occurs under lockscreen, but NOT while using emulator og device. I´ve tried setting up email notifications where in various trycatches, but no luck either, since the error im looking for also terminates that process..


    • Edited by jrasbr Sunday, May 3, 2015 4:54 PM
    Sunday, May 3, 2015 4:29 PM
  • Still no solution.. Anyone?

    Also i dont know how to debug it when error only occurs under lockscreen, but NOT while using emulator og device. I´ve tried setting up email notifications where in various trycatches, but no luck either, since the error im looking for also terminates that process..


    See here about enable debug tracing and use the Windows event log: https://msdn.microsoft.com/en-us/library/windows/apps/jj542415.aspx?f=255&MSPPError=-2147217396

    Best Regards,
    Please remember to mark the replies as answers if they help

    Monday, May 4, 2015 1:03 PM
  • Thank you, but i know that the Run method in my backgroundtask gets executed. I also know it works as it should, since audio plays both when app is in foreground, and when i push the "lock-screen/power" button on my lumia920, app continues to run and plays sounds when its supposed to. What i dont understand is why it does not work when its released - or when i test the deployed app on my phone without the usb-cable.
    Monday, May 4, 2015 7:58 PM
  • Hi Jrasbr,

    There's not enough information here to make much of a guess. Do you reproduce the same behavior with the sample or just with your app? Can you create a minimal, complete, and verifiable sample which demonstrates the problem and share that on your OneDrive?

    Does the audio stop immediately when you switch away from the app or does it wait for the current track to end? Does it stop only if you lock the system or if you switch away to another app?

    When you test without the usb-cable is the connection itself relevant or is it how you test? Are you debugging over the cable vs. running from the apps page without it? If you do the latter with the cable connected does it change anything?

    There are significant differences in application lifecycle when debugging (where apps won't suspend) and when not debugging (when they will).

    --Rob

    Monday, May 4, 2015 10:00 PM
    Owner