How can I transfer MP3 via HTTP in the background?

There are many examples of how to use a background audio agent, but very few show how to use a background audio stream and those that I found do not show mp3 streaming, but instead create a mock 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 transfer the MP3 URL, for example http://relay.radioreference.com:80/346246215 , and transfer it in the background? I also put BackgroundAudioPlayer.Instance.Play(); to reproduce it and what is it?

+4
source share
4 answers

yes, that’s enough. No streamer is needed if you set the background agent URL and call the BackgroundAudioPlayer.Instance.Play () function; background agent automatically transfers media file

+6
source

If you want to play streaming audio in a format / codec format that is not supported by your phone, you must do this with AudioStreamingAgent . If it is a supported codec, you can use AudioPlayerAgent (see Example here ).

Using AudioStreamingAgent is a non-trivial task and requires a deep understanding of the codec that you need to reproduce so that you can convert it to what the phone understands. I know if there was one person who did this for the H.264 stream, and it took a lot of time and a lot of effort to get it working. And before anyone asks: no, they cannot share the code from this project.

If you really need to go down this route, ManagedMediaHelpers (previously here ) is a good place to start, but yes, they do not cover all codecs, and it is probably very complicated and not something well documented on the Internet.

+5
source

You have a good example of AudioStreamingAgent on Github: https://github.com/loarabia/ManagedMediaHelpers .

I already tried, but only works when looking for the ID3 header in the stream.

+3
source

You can try my solution, just configure a little from the background agent to install a new track from mainPage.

SetTrack from the foreground

You can also save the trackList to Isostorage and read the background agent for playback.

0
source

Source: https://habr.com/ru/post/1398903/


All Articles