0
 public partial class MainPage : PhoneApplicationPage
  {
    // varibles and properties
    DispatcherTimer currentPosition = new DispatcherTimer();

    // Constructor
    public MainPage()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(MainPage_Loaded);
    }

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        myMediaElement.MediaOpened += new RoutedEventHandler(myMediaElement_MediaOpened);
        myMediaElement.MediaEnded += new RoutedEventHandler(myMediaElement_MediaEnded);
        myMediaElement.CurrentStateChanged += new RoutedEventHandler(myMediaElement_CurrentStateChanged);
        currentPosition.Tick += new EventHandler(currentPosition_Tick);

        myMediaElement.Source = new Uri("http://url2.bollywoodmp3.se/murder3/%5BSongs.PK%5D%20Murder%203%20-%2007%20-%20Hum%20Jee%20Lenge%20(Rock%20Version).mp3", UriKind.Absolute);
    }

    void myMediaElement_CurrentStateChanged(object sender, RoutedEventArgs e)
    {
        if (myMediaElement.CurrentState == MediaElementState.Playing)
        {
            currentPosition.Start();
            ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = false; // play
            ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = true;  // pause
            ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = true;  // stop
        }
        else if (myMediaElement.CurrentState == MediaElementState.Paused)
        {
            currentPosition.Stop();
            ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = true; // play
            ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = false;  // pause
            ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = true;  // stop
        }
        else
        {
            currentPosition.Stop();
            ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = true; // play
            ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = false;  // pause
            ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = false;  // stop
        }
    }

    void myMediaElement_MediaEnded(object sender, RoutedEventArgs e)
    {
        myMediaElement.Stop();
    }

    void myMediaElement_MediaOpened(object sender, RoutedEventArgs e)
    {
        pbVideo.Maximum = (int)myMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds;
        myMediaElement.Play();
    }

    void currentPosition_Tick(object sender, EventArgs e)
    {
        pbVideo.Value = (int)myMediaElement.Position.TotalMilliseconds;
    }

    private void Play_Click(object sender, EventArgs e)
    {
        myMediaElement.Play();
    }

    private void Pause_Click(object sender, EventArgs e)
    {
        myMediaElement.Pause();
    }

    private void Stop_Click(object sender, EventArgs e)
    {
        myMediaElement.Stop();
    }

}
}

这是我编写的用于从互联网播放音频文件的代码。在当前链接上,它播放的文件非常好,但我需要播放另一个文件,其链接是“http://108 . 166 . 161 . 206 : 8826/;stream.mp3”(没有空格)。当我用代码中的给定链接替换此链接时,应用程序没有播放任何内容。谁能帮我解决这个问题。提前谢谢。

4

1 回答 1

0

您拥有的流是 Shoutcast 媒体,这不是 Windows Phone 上实现的协议,但您可以使用Code plex中的Shoutcast MediaStreamSource !

于 2013-02-06T09:02:43.027 回答