none
[UWP] SystemMediaTransportControls issue in desktop store app using background audio

    Question

  • Hi,

    I'm working on a UWP app which uses background audio. The SystemMediaTransportControls (SMTC) properties is set from the background task.

    On the desktop, I could display the built-in media transport controls UI using a certain keyboard button combo on my laptop.

    THE ISSUE:

    However, tapping on the song title in the pop-up UI causes a new window to be opened for a split second and then closed. At the same time, audio that was playing in the background stopped playing abruptly. While the foreground app didn't generate any exception, attempting to access the background player instance (from the foreground) thereafter causes "The RPC server is unavailable" exception.

    The issue happens regardless whether the app is in the foreground or background. I was expecting the tapping the song title action would launch into the app (like in Groove Music).

    This issue is reproducible in the official UWP sample for background audio:
    https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BackgroundAudio

    as well as the TuneIn Radio app that's currently in the Store.

    Note that on the phone, tapping on the song title in the Universal Volume Control (UVC) correctly launches the app.

    I also noted that this issue does not affect media apps which does not use background audio. For example, the System Media Transport Controls UWP sample did not exhibit such issue.

    Is this a known platform bug. Any workarounds?

    Thanks!
    Wednesday, December 23, 2015 6:05 AM

Answers

  • I found the way to solve it.

    In the App.xaml.cs constructor add identify the device is mobile or desktop, such as:

    private SystemMediaTransportControls GetSMTC()
    {
       string deviceFamily = AnalyticsInfo.VersionInfo.DeviceFamily;
       
       if (deviceFamily.IndexOf("desktop", StringComparison.OrdinalIgnoreCase) >= 0) 
    {
          return Windows.Media.SystemMediaTransportControls.GetForCurrentView();
       }
       
       // other device
       return BackgroundMediaPlayer.Current.SystemMediaTransportControls;
    }

    try it. Thank you.

    • Proposed as answer by Pou MasonMVP Thursday, September 01, 2016 10:11 AM
    • Marked as answer by Jason-O Friday, September 02, 2016 6:11 AM
    • Unmarked as answer by Jason-O Friday, September 02, 2016 9:34 AM
    • Marked as answer by Jason-O Friday, September 02, 2016 9:46 AM
    Thursday, September 01, 2016 1:37 AM

All replies

  • Hello Jason-O,

    >>However, tapping on the song title in the pop-up UI causes a new window to be opened for a split second and then closed. At the same time, audio that was playing in the background stopped playing abruptly.

    I downloaded the UWP sample from github and run it. However I do not see you mentioned pop-up UI when I tapping on the song title? The background audio sample run as fine as I expected.

    So could you please provide some screenshots to show us your scenario and also share us a repro project?

    I also tried to download the app from the store, but I do not know what the step is to reproduce the issue you encountered, so please share us your detail steps.

    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.

    Thursday, December 24, 2015 3:05 AM
  • Hi Fred,

    >>So could you please provide some screenshots to show us your scenario and also share us a repro project?

    The UWP background audio sample is good enough to repro the issue. 

    Repro steps:

    1. Launch UWP sample app

    2. Play a tune. e.g. tap "Ring 1"

    3. On my Acer laptop, I use the Fn + Vol Up/Down button combo to display the built-in OS media transport controls; this is the pop-up UI I was referring to.

    4. Tap on the title (e.g. "Ring 1") in the pop-up and you'll see a new window open and close, and background audio is terminated. Ideally it should switch to the foreground app like in Groove Music and music continues to play.

    The pop-up UI should look similar to this (though the example screenshot is not related to the UWP sample): https://visualstudiomagazine.com/articles/2013/09/01/~/media/ECG/visualstudiomagazine/Images/2013/09/0913vsm_championFig1.ashx

    Thanks!


    • Edited by Jason-O Thursday, December 24, 2015 7:47 AM
    Thursday, December 24, 2015 7:46 AM
  • Hello,

    >>The UWP background audio sample is good enough to repro the issue.

    Yes, I could also reproduce it according to your steps, I would consult it internally and as soon as we get any result, we will post an update to here.

    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.

    Friday, December 25, 2015 2:10 AM
  • I also meted the problem.

    So, does the problem be solved?

    thank you.

    Monday, February 22, 2016 9:21 AM
  • I also meted the problem.

    So, does the problem be solved?

    Problem is still unresolved.
    Wednesday, February 24, 2016 9:12 AM
  • Any updates on this issue? I facing exactly the same problem here.
    Monday, June 27, 2016 12:11 PM
  • I found the way to solve it.

    In the App.xaml.cs constructor add identify the device is mobile or desktop, such as:

    private SystemMediaTransportControls GetSMTC()
    {
       string deviceFamily = AnalyticsInfo.VersionInfo.DeviceFamily;
       
       if (deviceFamily.IndexOf("desktop", StringComparison.OrdinalIgnoreCase) >= 0) 
    {
          return Windows.Media.SystemMediaTransportControls.GetForCurrentView();
       }
       
       // other device
       return BackgroundMediaPlayer.Current.SystemMediaTransportControls;
    }

    try it. Thank you.

    • Proposed as answer by Pou MasonMVP Thursday, September 01, 2016 10:11 AM
    • Marked as answer by Jason-O Friday, September 02, 2016 6:11 AM
    • Unmarked as answer by Jason-O Friday, September 02, 2016 9:34 AM
    • Marked as answer by Jason-O Friday, September 02, 2016 9:46 AM
    Thursday, September 01, 2016 1:37 AM
  • I found the way to solve it.

    In the App.xaml.cs constructor add identify the device is mobile or desktop, such as:

    private SystemMediaTransportControls GetSMTC()
    {
       string deviceFamily = AnalyticsInfo.VersionInfo.DeviceFamily;
       
       if (deviceFamily.IndexOf("desktop", StringComparison.OrdinalIgnoreCase) >= 0) 
    {
          return Windows.Media.SystemMediaTransportControls.GetForCurrentView();
       }
       
       // other device
       return BackgroundMediaPlayer.Current.SystemMediaTransportControls;
    }

    try it. Thank you.


    Thank you for following up on this, one question though: Who calls GetSMTC() in your app.xaml.cs?? how does this method fix the crash caused by clicking on the SMTC UI?? Can you explain more? Thank you
    Friday, September 02, 2016 9:30 AM
  • use the GETSMTC() in the app.xaml.cs constructor:

    public App()
    {
      GetSMTC();
    }

    Why need use the difference source?

    If you developed the Windows 8.1 Store app, maybe you will know it.

    In the Windows 8.1 Store app, only used MediaElement and set AudioCategory is BackgroundCapableMedia, the app be supported background audio.

    Based on the reason, I try to use the Windows.Media.SystemMediaTransportControls.GetForCurrentView(); to control SMTC for desktop. It's work. fixed the crash issue.

    In the mobile the app must be used BackgroundMediaPlayer.Current.SystemMediaTransportControls , because mobile only one background Player.


    Monday, September 12, 2016 5:52 AM