如何在后台通过HTTP传输MP3?

Gab*_*ves 4 c# windows-phone-7

有很多关于如何使用背景音频代理的例子,但是很少有人展示如何使用背景音频流代理,而我发现的那些代码不显示流式mp3,而是创建一个假装流.

当我创建一个新的Windows Phone Audio Streaming Agent项目时,它给了我:

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

我如何给它一个像http://relay.radioreference.com:80/346246215这样的MP3网址并让它在后台播放?我也把BackgroundAudioPlayer.Instance.Play();它玩了,就是这样吗?

San*_*thu 6

是的,这就足够了如果你将URL设置为后台代理并调用函数BackgroundAudioPlayer.Instance.Play(); 后台代理自动流式传输媒体


Mat*_*cey 5

如果您想以手机本机不支持格式/编解码器播放流式音频,则必须使用AudioStreamingAgent.如果它是受支持的编解码器,您可以使用AudioPlayerAgent(请参阅此处的示例).

使用AudioStreamingAgent是一项非常重要的任务,需要深入了解您需要播放的编解码器,以便将其转换为手机可以理解的内容.我知道如果一个人做了这个,对于一个H.264流,并花了很长时间和很多头发拉动它的工作.在任何人问之前:不,他们无法共享该项目的代码.

如果你真的必须沿着这条路走下去,ManagedMediaHelpers(以前在这里)是一个很好的起点,但是,它们并不涵盖所有的编解码器,这可能是非常复杂的,并且没有在Web上有详细记录.