0

我想在我的Windows Phone應用程序中播放shoutcast音頻。我有我從一些網站得到的以下代碼。通過URL的BackgroundAudioPlayer

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

     } 


    } 
} 
} 

現在,事情是,這個例子播放一個內部文件。而且由於我是新手入門,所以我不明白爲了給這個玩家一個播放網址應該遵循什麼規定。請幫助通過URL在BackgroundAudioPlayer中播放音頻。任何形式的幫助表示讚賞,因爲我急需這一點。感謝所有提前..

+0

您是否已經創建了背景[AudioAgent](http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394039(v = vs.105).aspx)? –

+0

不,我可以稍微解釋一下,因爲這些讓我感到困惑。 – Akshat

回答

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

};