Add AudioBackground to Sample Player

Jun 15, 2014 at 7:34 PM
Hello.I'm new on c# and windows phone.i have create a application that stream some channel.every think work well,but now i want to add radio.so on app bar i created a button witch send to a new xaml page.on that page i copy all the code just like the mainpage.xaml and mainpage.xaml.cs on the BackgroundAudioSample.WP8 but it diden't worked. i have create that from the source.
Coordinator
Jun 17, 2014 at 8:18 PM
For background audio, you also need to tell the OS how to play that stuff as a background task. BackgroundAUdio.Sample.WP8 has this in its WMAppManifest.xml:
      <ExtendedTask Name="BackgroundTask">
        <BackgroundServiceAgent Specifier="AudioPlayerAgent" Name="SM.BackgroundAudioPlaybackAgent" Source="SM.Media.BackgroundAudioStreamingAgent.WP8" Type="SM.Media.BackgroundAudioStreamingAgent.AudioPlayer" />
        <BackgroundServiceAgent Specifier="AudioStreamingAgent" Name="SM.BackgroundAudioStreamingAgent" Source="SM.Media.BackgroundAudioStreamingAgent.WP8" Type="SM.Media.BackgroundAudioStreamingAgent.AudioTrackStreamer" />
      </ExtendedTask>
Jun 19, 2014 at 11:47 AM
Edited Jun 19, 2014 at 11:51 AM
But if I have somethink like this:
Code:
 private void Button_Click(object sender, RoutedEventArgs e)
        {
            string link = (sender as Button).Tag.ToString();
           //Tag = http://freshfm.md/freshfm.m3u
             BackgroundAudioPlayer.Instance.Track = new AudioTrack(null, null, null, null, null, link, EnabledPlayerControls.All);
             BackgroundAudioPlayer.Instance.Play();
        }
Log:
++++ Starting http://217.12.115.74:8000/ at 6/19/2014 2:45:33 PM +03:00.  Total memory: 1.01 MiB
<8.81MiB/9.01MiB>
The thread 0xd98 has exited with code 259 (0x103).
<8.75MiB/9.01MiB>
AudioPlayer.OnUserAction() track.Source <none> track.Tag <none> action Play
<8.75MiB/9.01MiB>
Coordinator
Jun 19, 2014 at 8:43 PM
The actual background audio runs in a separate process. The only way the OS knows what you want to run in that process is through those entries in the manifest. What you are talking to in the above code is a proxy object that forwards calls to the real object in the other process.

Background audio overview for Windows Phone 8
Jun 20, 2014 at 6:49 AM
Thanks for your reply! If you have some time can you give an example how to play a stream in background like this: http://217.12.115.74:8000/
Coordinator
Jun 24, 2014 at 5:15 PM
Microsoft's HTTP code is pretty touchy. It doesn't return any headers for this request, so the code that tries to detect the stream's content type fails. You could try using an alternate HTTP stack (this might work for you, but would require a bit of work to adapt the HttpWebRequestWebReader/HttpWebRequestWebReaderManager implementation to use the Mono implementation instead of the Microsoft one), you provide an IContentTypeDetector that returns ContentTypes.Aac when it recognizes that url, or you could bypass the content type detection code by forcing it by setting MediaStreamFascade's ContentType.

For example, adding the following to AudioTrackStreamer's InitializeMediaStream()
            _mediaStreamFacade.ContentType = ContentTypes.Aac;
gets the stream playing. A more general solution would probably want to look at the stream's url before forcing the type.