There are many examples on how to use the Background Audio Agent but very few show how to use the Background Audio Streaming Agent and the ones that I found don't show streaming mp3 but instead create a pretend stream.
When I create a new Windows Phone Audio Streaming Agent project, it gives me:
public class AudioTrackStreamer : AudioStreamingAgent
{
/// <summary>
/// Called when a new track requires audio decoding
/// (typically because it is about to start playing)
/// </summary>
/// <param name="track">
/// The track that needs audio streaming
/// </param>
/// <param name="streamer">
/// The AudioStreamer object to which a MediaStreamSource should be
/// attached to commence playback
/// </param>
/// <remarks>
/// To invoke this method for a track set the Source parameter of the AudioTrack to null
/// before setting into the Track property of the BackgroundAudioPlayer instance
/// property set to true;
/// otherwise it is assumed that the system will perform all streaming
/// and decoding
/// </remarks>
protected override void OnBeginStreaming(AudioTrack track, AudioStreamer streamer)
{
//TODO: Set the SetSource property of streamer to a MSS source
NotifyComplete();
}
/// <summary>
/// Called when the agent request is getting cancelled
/// The call to base.OnCancel() is necessary to release the background streaming resources
/// </summary>
protected override void OnCancel()
{
base.OnCancel();
}
}
How do I give it a MP3 URL like http://relay.radioreference.com:80/346246215 and have it stream it in the background? Also do I put BackgroundAudioPlayer.Instance.Play();
to play it and that's it?
yes, that is enough No need of streamer, if you set the URL to the background agent and call the function BackgroundAudioPlayer.Instance.Play(); the background agent automatically streams the media