【问题标题】:BackgroundAudioPlayer via URL通过 URL 的 BackgroundAudioPlayer
【发布时间】:2013-06-28 10:37:26
【问题描述】:

我想在我的 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 中播放音频。任何形式的帮助表示赞赏,因为我迫切需要这个。提前谢谢大家..

【问题讨论】:

  • 您是否已经创建了背景AudioAgent
  • 不,我能解释一下吗,因为这些让我很困惑。

标签: windows-phone-7 windows-phone-8 windows-phone shoutcast background-audio


【解决方案1】:

您基本上创建了一个 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();

【讨论】:

    【解决方案2】:
               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)
    

    };

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多