[英]Cannot play media Element programmatically
我在Windows Phone 8中開發了一個應用程序。我有一個列表,其中包含來自網絡的mp3,中介無法播放它們。
這是我的代碼
private void Button_Click_1(object sender, RoutedEventArgs e)
{
play.Source = new Uri("http://n1.xtek.gr/ime_ploigos/rest/narrations/gr/10.mp3",UriKind.RelativeOrAbsolute);
play.MediaOpened += new RoutedEventHandler(note1_MediaOpened);
}
void note1_MediaOpened(object sender, RoutedEventArgs e)
{
play.Play();
}
xaml是:
<MediaElement HorizontalAlignment="Left" Height="100" Margin="167,538,0,0" VerticalAlignment="Top" Width="100" Name="play" AutoPlay="True"/>
我已經在xaml中嘗試過並播放了,但是沒有編程方式。 有人能幫我嗎 ?
我認為您不需要在MediaOpened事件中播放。 將Source分配給MediaPlayer后,只需執行.Play
只需將其添加到按鈕單擊事件
private void Button_Click_1(object sender, RoutedEventArgs e)
{
play.Source = new Uri("http://n1.xtek.gr/ime_ploigos/rest/narrations/gr/10.mp3",UriKind.RelativeOrAbsolute);
play.Play();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.