locked
Audio Background Task cause to the forgraound app to terminate when it's not in forground.

    Question

  • I have an app that plays audio from different Uri (from the web). It works great, and also the background agent seems to work great. But when I invoke BackgroundMediaPlayer.Current.SetSource(Some URI) it seems that every time that the app is not in forgraound it terminates. if I don't start the sound, the app works as expected (not suspended and terminates unless the os needs the resources). The problem is really big for me, since I cannot use the In app Purchase since as soon as the store starts, the app terminates, and the Purchases terminates too.

    Pleases I have tried to search for answer for quite a time now. I have looked a lot of times at the MSDN example, and it seems that I do every thing currently.

    Thanks

    Sunday, October 5, 2014 10:52 PM

All replies

  • OK, I have add logs into MSDN universal app Music player example, and it have the same problem.

    Also, if I try to use the in app purchase in there (using the Simulator) it terminates the purchase just like in my app.

    It seems as a common problem for any music player that is built on top of the Universal app's WinRT Api.

    Have any one tried and succeed to solve this?

    Monday, October 6, 2014 10:05 AM
  • I have finally figured out a work around. It works, but I really don't like it.

    The only way that the Foreground app will not terminate on suspened it to kill the Background audio task.

    I have tried many ways to do that, and the only way I found out that works currectly, is to send a message to the background task for cancelation, and the background task should releass all the events and resources that it is registered to, and throw exception in the message recived from foreground callback.

    Before rising the request for the sotre, we need to wait a delay (I have found 1 second as very afficent) and then lunch the store.

    If any one can find better solution, please help, this is a very bad behavior.

    Monday, October 6, 2014 2:39 PM
  • Hi YossiStarz,

    I cannot find the code example you are using in universal app code sample from here. Can you provide a repro project? Use your OneDrive and share a link here. I will look into it and let you know the result.

    Regards,


    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.

    Tuesday, October 7, 2014 5:18 AM
    Moderator
  • Thank you very much for you're response.

    This is the project I have altered:

    https://onedrive.live.com/redir?resid=85F0CB03D9A74D4%2160966

    The only changes I have made is adding Toast messages On Lunching and On Suspending, Since it can't run with debugger attached (If you do, the process will not terminate unless you request the debugger to do so).

    Also I have add a store button, that opens an in app purchase (witch this is my main problem). when you open the store without background task that is running with music (it is important since it occurs right after the SetSource), it works ok. If you started the background task music, you will see that the store  terminates with the foreground process after a few seconds (5 to 15 seconds). From that moment you can't open the In App purchase and prevent it to terminate after the 5 to 15 seconds unless you cause the background process to cancel. In my app I am sending a message to the background task and then throws an exception (This was the only way that I found it working).

    Also, you can see that when the app is opened after the suspending with previews state of "Terminated".

    Thanks again :)

    Tuesday, October 7, 2014 9:06 AM