【问题标题】:Audio and Video playing in Windows 10 universal app?在 Windows 10 通用应用程序中播放音频和视频?
【发布时间】:2015-10-24 00:15:02
【问题描述】:

我需要在 Windows 应用程序中播放音频和视频,在该应用程序中我从网络调用获取 Url,并且我需要将 Url 添加到 Source。 我试过这种方式,但是没有播放视频或播放音频。 有人帮助我如何实现这一目标? 有没有其他方法可以做到这一点?

提前致谢。

我的 xaml 代码:

<StackPanel HorizontalAlignment="Center" Grid.Row="3">

         <MediaElement x:Name="media" 
              Source="Videos/video1.mp4" 
              Width="400" 
              AutoPlay="False"
              AreTransportControlsEnabled="True" />

            <StackPanel Orientation="Horizontal"
            HorizontalAlignment="Center">

                <Button Content="Play" Click="Play_Click"/>
                <Button Content="Pause" Click="Pause_Click"/>
                <Button Content="Stop" Click="Stop_Click" />

            </StackPanel>
        </StackPanel>

我的cs代码:

  async void Play_Click(object sender, RoutedEventArgs e)
    {
        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            Uri pathUri = new Uri("https://www.youtube.com/watch?v=sOEg_YZQsTI");
            media.Source = pathUri;
            Util.debugLog("PLaying ...");
            media.Play();
            media.Volume = 40;
        });
    }

    async void Pause_Click(object sender, RoutedEventArgs e)
    {
        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            Util.debugLog("Paused .. ");
            media.Pause();
        });
    }

    async void Stop_Click(object sender, RoutedEventArgs e)
    {
        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            Util.debugLog("Stoped ..");
            media.Stop();
        });
    }


    void Media_MediaFailed(object sender, ExceptionRoutedEventArgs e)
    {
        // Handle failed media event
    }

    void Media_MediaOpened(object sender, RoutedEventArgs e)
    {
        // Handle open media event
    }

    void Media_MediaEnded(object sender, RoutedEventArgs e)
    {
        // Handle media ended event
    }

【问题讨论】:

  • 在调用Play 之后,您是否在Media_MediaOpened 事件处理程序中结束?

标签: c# windows xaml windows-10 uwp


【解决方案1】:

如果我没记错的话,您目前正在指定一个网站作为MediaElement 的来源。那是行不通的。如果您想嵌入 youtube 内容,您有两种可能性:

  1. 将网页嵌入WebView
  2. 将视频本身的网址设置为Source

【讨论】:

  • 在这种情况下,我们如何控制播放,因为一旦我们将视频作为 webview 的源,视频将开始在 rstp 播放器中播放,我们如何控制它?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-16
  • 2010-10-24
  • 2012-11-10
  • 2015-05-14
  • 1970-01-01
相关资源
最近更新 更多