locked
WP8.1 Playing audio in background from http widget

    Question

  • Hi,

    I'm building an app for one of music platforms. I want to add to my app playing music function from that platform with SystemMediaTransportControls. The problem is that playing music can only be controlled by http widget. There is no direct stream url so I cannot use mediaplayer instance in background task. I was thinking on using webview control inside background process but I don't know whether it would stream audio in that form.

    For test purpose I've build Page with WebView control and redirected it to http widget. I can play music in that form but when I lock the phone, music stops playing. Another option from above would be enabling music to play after going app to suspended state.

    Can anyone help me?

    Monday, March 30, 2015 9:31 AM

All replies

  • Unfortunately, you have only one option to play audio in background in wp8.1. The background mediaplayer exists out of your app, can play audio when your app suspend. WebView control sit in XAML tree in your app, suspend together with the app, I don’t think there is option to let it play audio in background. You still need to find a way to use SYstemMediaTransportControls for this purpose.

    Tuesday, March 31, 2015 8:06 AM
  • Hello,

    Nithak is correct. You must use the background media player to play background audio on the Windows Phone 8.1 platform. You cannot use the WebView from a background task. The media transport controls are directly integrated into the background media player and cannot be used independently.

    You said: "There is no direct stream url so I cannot use mediaplayer instance in background task."

    There must be a URL that the page is connecting to and receiving audio data from. If you are not the owner of the website that the audio originates from, you should contact the owner of the website and ask them if their audio protocol is documented. If you have access to the documented protocol you can write your own custom MediaStreamSource to connect to, parse and play the custom audio stream.

    I hope this helps,

    James


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

    Tuesday, March 31, 2015 9:14 PM
    Moderator
  • Hi,

    thanks for an answer. Basically it's not that simple. The owner of the api said me that they want to control what and how many times people are listening to songs and they provide a HTTP widget which is a <IFRAME> with they own HTTP page. I can only control playing, pausing and loading songs by JavaScript. So I thought I will wrap their widget to the WebView control which I will use in the background task to play music. I lost many hours trying to do that with no result. I think that MediaStreamSource wouldn't help me at all.

    Artur

    Wednesday, April 1, 2015 9:36 PM
  • Hello,

    Unfortunately hosting the WebView from a background task is not supported and likely won't work as expected. Unfortunately we don't support this scenario as it is very uncommon. I would recommend that you work with the content provider to see if they can provide a more direct mechanism for you to access their content that can mimic the features of the HTTP widget in the context of a MediaStreamSource.

    -James


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

    Thursday, April 2, 2015 6:14 PM
    Moderator
  • You can refer to this URL

    http://www.jayway.com/2014/04/24/windows-phone-8-1-for-developers-the-background-media-player/

    Windows Phone 8.1 for developers – the Background Media Player


    Saturday, April 4, 2015 11:55 AM
  • You may refer to this URL,

    https://msdn.microsoft.com/en-us/library/windows/apps/hh202978(v=vs.105).aspx

    Tuesday, April 7, 2015 1:07 AM
  • This post is not helpful in the context of this thread. I would ask that you please delete this post so that others don't get confused by it. 

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

    Tuesday, April 7, 2015 10:05 PM
    Moderator
  • This post is not helpful in the context of this thread. I would ask that you please delete this post so that others don't get confused by it. 

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

    Tuesday, April 7, 2015 10:05 PM
    Moderator