简体   繁体   English

无法以编程方式播放媒体元素

[英]Cannot play media Element programmatically

I developed an app in Windows Phone 8. I have a list with mp3 from web and a mediaelement can't play them. 我在Windows Phone 8中开发了一个应用程序。我有一个列表,其中包含来自网络的mp3,中介无法播放它们。

This is my code 这是我的代码

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

And xaml is : xaml是:

<MediaElement HorizontalAlignment="Left" Height="100" Margin="167,538,0,0" VerticalAlignment="Top" Width="100" Name="play" AutoPlay="True"/>

I have try it in xaml and play it but programmatically not. 我已经在xaml中尝试过并播放了,但是没有编程方式。 Can someone help me ? 有人能帮我吗 ?

I do not think you need to Play inside MediaOpened event. 我认为您不需要在MediaOpened事件中播放。 Just execute .Play after assigning Source to the MediaPlayer 将Source分配给MediaPlayer后,只需执行.Play

Just add this to button click event 只需将其添加到按钮单击事件

    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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM