0

I want to play a shoutcast audio in my windows phone app. I have the following code which I got from some website.

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

        }


    }
}
}

Now, the thing is that this examples plays an internal file. And since I am newbie to windows, I cannot understand what shall be followed to give this player a shoutcast url. Please help to play audio in BackgroundAudioPlayer via URL. Any kind of help appreciated as I am in urgent need of this. Thanx to all in advance..

Shawn Kendrot
  • 12,425
  • 1
  • 25
  • 41
Aishvarya Jaiswal
  • 1,793
  • 6
  • 34
  • 72

2 Answers2

0

You basically create an AudioTrack and pass it to the player. Like

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();
David Gordon
  • 554
  • 2
  • 8
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)

};