This project has moved and is read-only. For the latest updates, please go here.

Add AudioBackground to Sample Player

Jun 15, 2014 at 8: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 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.
Jun 17, 2014 at 9: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" />
Jun 19, 2014 at 12:47 PM
Edited Jun 19, 2014 at 12:51 PM
But if I have somethink like this:
 private void Button_Click(object sender, RoutedEventArgs e)
            string link = (sender as Button).Tag.ToString();
           //Tag =
             BackgroundAudioPlayer.Instance.Track = new AudioTrack(null, null, null, null, null, link, EnabledPlayerControls.All);
++++ Starting at 6/19/2014 2:45:33 PM +03:00.  Total memory: 1.01 MiB
The thread 0xd98 has exited with code 259 (0x103).
AudioPlayer.OnUserAction() track.Source <none> track.Tag <none> action Play
Jun 19, 2014 at 9: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 7: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:
Jun 24, 2014 at 6: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.