0

I have a medialement with a url-source which streams a radio station. Everything works fine and music plays as expected! When I press the shutdown button and the phone locks, the streaming stops. How can I fix that? Even if I press the "flag" button, I see my main screen but the music stops :/ thanks in advance

metz
  • 11
  • 2

1 Answers1

0

You must use the BackgroundAudioPlayer to accomplish this.

See this msdn article for more info and my post explaining some gotchas of the BackgroundAudioPlayer

Taking the sample from the msdn link. I changed the PlayTrack method to:

private void PlayTrack(BackgroundAudioPlayer player)
{
       var track = new AudioTrack(
                    new Uri("http://m1.onweb.gr/1055rock"),
                    "Online",
                    "Music",
                    string.Empty,
                    null,
                    string.Empty,
                    EnabledPlayerControls.Pause);
        if (player != null)
        {
            player.Track = track;
        }
}

And I get the errors noted below. How are you trying to start the player?

Community
  • 1
  • 1
Shawn Kendrot
  • 12,425
  • 1
  • 25
  • 41
  • The source for the track can be a URI as well. – Shawn Kendrot May 30 '12 at 01:43
  • I set the url of the radio station as a "new AudioTrack" and although "name" and "artist" appear on the playlist (I check that by pressing up/low volume) nothing happens! No music playing or smthing :/ If I set this url in a mediaElement it works fine! – metz May 30 '12 at 13:30
  • Did you add a new Windows Phone Audio Playback Agent to your solution? – Shawn Kendrot May 30 '12 at 14:49
  • yes..I think I did it right cause the song I add appears fine on the now playing menu that pops when I press volume up/down! The problem is that there is no sound :s – metz May 30 '12 at 15:13
  • what is the URI you are using – Shawn Kendrot May 30 '12 at 17:34
  • I have tried all these: [link](http://m1.onweb.gr/1055rock) [link](http://m1.onweb.gr/1055rock?MSWMExt=.asf) [link](http://wm1.greekstream.net/1055) but non of them worked.. – metz May 30 '12 at 19:56
  • Put a breakpoint in the OnError method of your AudioPlayer you will see the following error: Message "-1072872837", HResult: -2146233088. Might have something to do with the support media for WP7: http://msdn.microsoft.com/en-us/library/ff462087(v=vs.92).aspx – Shawn Kendrot May 30 '12 at 20:46
  • I don't get any errors.. any other ideas? how can a mediaelement stream that link and the backgroundaudio cant? – metz May 30 '12 at 22:09
  • I start it this way: `BackgroundAudioPlayer.Instance.Track = new AudioTrack(new Uri("http://m1.onweb.gr/1055rock", UriKind.Absolute), "Rock Radio", "Radio", "rock", null); BackgroundAudioPlayer.Instance.Play();` – metz May 31 '12 at 19:07