【问题标题】:Cannot play media Element programmatically无法以编程方式播放媒体元素
【发布时间】:2016-03-04 13:16:35
【问题描述】:

我在 Windows Phone 8 中开发了一个应用程序。我有一个来自网络的 mp3 列表,但 mediaelement 无法播放它们。

这是我的代码

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 中尝试过它并播放它,但以编程方式没有。有人能帮我吗 ?

【问题讨论】:

    标签: c# xaml windows-phone-8 windows-phone


    【解决方案1】:

    我认为您不需要在 MediaOpened 事件中播放。将Source分配给MediaPlayer后执行.Play

    【讨论】:

      【解决方案2】:

      只需将此添加到按钮单击事件

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-28
        • 1970-01-01
        相关资源
        最近更新 更多