none
[UWP]Windows 10. How to trigger playing audio in the background from the other Background task. RRS feed

  • Question

  • I need to to start playing sound from Background Task. My background task is initiated via GattServiceProviederTrigger. So I have Gatt Server running in the background. When certain Write Request is handled inside my Background task I have to start playing the sound. I need to do it without launching the Application. Please advice how can I achieve that.

    According to this topic "wp 8.1 start sound from a background task (not to background BUT FROM BACKGROUND!! there is the possibility to use toast and do a workaround.

    I hope there is the way to trigger Bg task from the other Bg task without launching the app.

    Thank you



    Wednesday, September 11, 2019 6:33 PM

All replies

  • Hi,

    For UWP app that running in Windows 10, there is a much easy way for playing audio in the background. You just need to add the Background Media Playback capability in the manifest file. Then your app will be able to play media in the background. You could register the background task and handle the Completed event of the background. Then in the Complete event handler play the audio.

    There is a sample about background task:BackgroundTask. You could refer scenario 1 about how to handle the Complete event of the background task. And you could refer this document:Play media in the background about how to add Background Media Playback capability in the manifest file.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 12, 2019 1:19 AM
    Moderator
  • This is the way I implemented it actually - trigger the audio play upon Task Completed of my Gatt Server BG task inside my Application where I registered the Gatt Server BG trigger.

    Just wanted to confirm that Completed event will be handled by the app if the app is in the Suspended or ClosedByUser modes?

    I need to be able to play sound even if the User closed application or the app is not visible.

    Thank you!

    Thursday, September 12, 2019 2:52 PM
  • Hi,

    The answer is no, I've tested this in the Background task sample. I tried to play music using mediaplayer in the Completed event. When I minimize the app and the app is suspended, the music won't play until I bring the app to foreground again. 

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 16, 2019 8:44 AM
    Moderator
  • Ok thank you for response.

    I tried The toast notification approach with custom audio to play and looks like this is the way to go in my use case. Toast notification can be initiated from my GAtt server Background task and the notification will be displayed even when foreground app is closed or the screen is locked.

    However the moment the laptop goes to modern stand by mode - the notification will not be played....

    My next question is how to wake up the device from modern standby mode upon processing a command inside the Gatt Server Background task?

    Thank you


    Monday, September 16, 2019 9:19 PM
  • Hi,

    According to the document:Wakes SoC and can turn on display the notifications from UWP apps could wake up the device from modern standby. But you need to make sure that your notification is toast notification and if your device is on AC power, notifications of all priorities from UWP apps will be delivered.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 17, 2019 2:30 AM
    Moderator