2012-02-28 79 views
4

有很多关于如何使用背景音频代理的例子,但很少展示如何使用背景音频流媒体代理以及我发现的不显示流媒体mp3,而是创建一个假装流。如何在后台通过HTTP流式传输MP3?

当我创建一个新的Windows Phone音频流传输代理项目,它给了我:

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(); 
    } 
} 

我怎么给它一个MP3 URL像http://relay.radioreference.com:80/346246215,并在后台流呢?我也可以放BackgroundAudioPlayer.Instance.Play();来玩,就是这样吗?

回答

6

是的,这就足够了如果您将URL设置为后台代理并调用函数BackgroundAudioPlayer.Instance.Play();则不需要流化器。后台代理自动流媒体

+0

如何设置网址?哪里? – 2012-02-29 07:56:13

+1

请参阅此链接http://msdn.microsoft.com/en-us/library/hh202978%28v=vs.92%29.aspx。在后台音频代理项目中,将AudioPlayer.cs文件中的音频播放列表添加为新的轨道。 (新Uri(“http://relay.radioreference.com:80/346246215”,UriKind.RelativeorAbsolute), “AlbumName”, “Artist”, “Ninja Tuna”, Artpath); – Santhu 2012-02-29 08:30:52

+0

谢谢。我会看看这是否会奏效。 – 2012-02-29 20:01:35

3

你有一个Github上的AudioStreamingAgent的好例子:https://github.com/loarabia/ManagedMediaHelpers

我已经试过了,但只在流上找到ID3头时才起作用。

+0

谢谢。我已经尝试过这个例子,它们使它不仅难以理解,而且对我也不适用。如果它帮助别人,我仍会投票。 – 2012-02-29 20:01:24

5

如果要播放format/codec which is not natively supported by the phone中的流式音频,您必须使用AudioStreamingAgent。如果它是支持的编解码器,则可以使用AudioPlayerAgent(请参阅示例here)。

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

如果你真的必须这条路往下走,ManagedMediaHelpers(以前here)是一个很好的起点,但肯定的,它们并不包括所有的编解码器,这是潜在的,非常复杂,而不是好东西记录在网上。

0

你可以试试我的解决方案,只需从后台代理自定义设置新的轨道从mainPage。

SetTrack from foreground

您还可以保存曲目,以Isostorage和读取从后台代理玩。