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
If you want to play streaming audio in a format/codec which is not natively supported by the phone you must do it with an AudioStreamingAgent
. If it is a supported codec, you can use an AudioPlayerAgent
(see sample here).
Using an AudioStreamingAgent is a nontrivial task and requires a deep understanding of the codec you need to play so you can convert it to something the phone understands. I know if one person who did this, for a H.264 stream, and it took a long time and much hair pulling to get it working. And before anyone asks: No, they are not able to share code from that project.
If you really must go down this route, the ManagedMediaHelpers (previously here) are a good place to start, but yes, they don't cover all codecs and this is, potentially, very complicated and not something well documented on the web.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With