2013-02-06 67 views
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(); 
    } 

} 
} 

這是我編寫的用於播放來自Internet的音頻文件的代碼。在當前鏈接中它播放的文件非常好,但我需要播放另一個文件,其鏈接是「http:// 108。166。161。206:8826 /; stream.mp3」(不含空格)。當我用代碼中的給定鏈接替換此鏈接時,應用程序不會播放任何內容。任何人都可以請幫助我解決這個問題。提前Thanx。應用程序工作在一個鏈接上,但不在其他

+0

將您的鏈接(URL)粘貼到瀏覽器中並確保其正常工作 – nkchandra

回答

0

您擁有的流是Shoutcast媒體,這不是Windows Phone上實現的協議,但您可以使用代碼plex中的Shoutcast MediaStreamSource

相關問題