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”(不含空格)< / strong>即可。当我用代码中的给定链接替换此链接时,应用程序没有播放任何内容。任何人都可以帮我解决这个问题。提前完成。
答案 0 :(得分:0)
您拥有的流是Shoutcast媒体,这不是Windows Phone上的已实施协议,但您可以使用Code plex中的Shoutcast MediaStreamSource!