0

我想在我的 Windows Phone 应用程序中播放广播音频。我有以下从某个网站获得的代码。

 namespace WPBackgroundAudioDemo
{
public partial class MainPage : PhoneApplicationPage
{
    // Constructor
    public MainPage()
    {
        InitializeComponent();
        SaveToIsoStore();
    }

    private void buttonStart_Click(object sender, RoutedEventArgs e)
    {
        if (BackgroundAudioPlayer.Instance.PlayerState != PlayState.Playing )
            BackgroundAudioPlayer.Instance.Play();

    }

    private void buttonStop_Click(object sender, RoutedEventArgs e)
    {
        if (BackgroundAudioPlayer.Instance.PlayerState != PlayState.Stopped)
            BackgroundAudioPlayer.Instance.Stop();
    }

    private void SaveToIsoStore()
    {
        IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication();
        if (!isolatedStorageFile.FileExists("Lullabies.mp3"))
        {
            StreamResourceInfo resource = Application.GetResourceStream(new Uri("Lullabies.mp3", UriKind.Relative));

            using (IsolatedStorageFileStream isolatedStorageFileStream = isolatedStorageFile.CreateFile("Lullabies.mp3"))
            {
                int chunkSize = 1024;
                byte[] bytes = new byte[chunkSize];
                int byteCount;

                while ((byteCount = resource.Stream.Read(bytes, 0, chunkSize)) > 0)
                {
                    isolatedStorageFileStream.Write(bytes, 0, byteCount);
                }
            }

        }


    }
}
}

现在,问题是这个例子播放的是一个内部文件。而且由于我是 Windows 新手,我不明白应该遵循什么来给这个播放器一个直播网址。请帮助通过 URL 在 BackgroundAudioPlayer 中播放音频。任何形式的帮助表示赞赏,因为我迫切需要这个。提前谢谢大家..

4

2 回答 2

0
           private static List<AudioTrack> _playList = new List<AudioTrack>

            {   

       new AudioTrack(new Uri("Default Project.aac", UriKind.Relative), 
                "Kalimba", 
                "Mr. Scruff", 
                "Ninja Tuna", 
                null),


new AudioTrack(new Uri("Rainy Mood + The Cinematic Orchestra.aac", UriKind.Relative), 
                "Maid with the Flaxen Hair", 
                "Richard Stoltzman", 
                "Fine Music, Vol. 1", 
                null),

new AudioTrack(new Uri("Rainy Mood + The Cinematic Orchestra.aac", UriKind.Relative), 
                "Sleep Away", 
                "Bob Acri", 
                "Bob Acri", 
                null),

// A remote URI
new AudioTrack(new Uri("http://traffic.libsyn.com/wpradio/WPRadio_29.mp3", UriKind.Absolute), 
                "Episode 29", 
                "Windows Phone Radio", 
                "Windows Phone Radio Podcast", 
                null)

};

于 2014-09-20T20:10:10.497 回答
0

您基本上创建了一个 AudioTrack 并将其传递给播放器。喜欢

var track =
    new AudioTrack(
        new Uri(your url here, UriKind.Absolute),
        "Track Name",
        string.Empty,
        string.Empty,
        null);

BackgroundAudioPlayer.Instance.Track = track;
BackgroungAudioPlayer.Instance.Play();
于 2013-06-28T22:25:44.270 回答