XAML 视频插入未显示 [英] XAML The video insert didn't display

查看:36
本文介绍了XAML 视频插入未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次在 xaml 中编程,我试图在后面的代码中插入视频,但没有显示显示屏变黑.我知道你们可以帮助我,谢谢大家的帮助.

This is my first time programing in xaml and I'm trying to insert a video in a code behind but didn't display the display go black. I know you guys can help me thank you all for the help.

这是我的 xaml.cs 代码.

This is my xaml.cs code.

namespace App_Videos_Test
{

public sealed partial class MainPage : Page
{
    public MainPage()
    {

        this.InitializeComponent();
        PlayVideo(); 

    }

    private async void PlayVideo()
    {
        string VideoUrl = "http://www.youtube.com/watch?v=2rJwYN_SmOU";
        var url = await YouTube.GetVideoUriAsync(VideoUrl, YouTubeQuality.Quality360P);
        var YoutubePlayer = new MediaElement();
        YoutubePlayer.Source = url.Uri;
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
    }
  }
 }

这是我的 xaml 代码.

And this is my xaml code.

<Grid x:Name="grdVideo" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <MediaElement  x:Name="meTestVideo" HorizontalAlignment="Left" Height="578" Margin="188,128,0,0" VerticalAlignment="Top" Width="1000"/>
</Grid>

推荐答案

在您背后的代码中,您正在创建一个新的 MediaElement 组件,并让它播放您的视频.

In your code behind you are creating a new MediaElement component, and getting that to play your video.

想必您真正想要做的是在您已经在 XAML 中创建的 MediaElement 上播放视频 - 名为 meTestVideo 的那个.在您的 PlayVideo() 方法中,您希望引用现有的 MediaElement,如下所示:

Presumably what you really want to do is play the video on the MediaElement you've already created in the XAML - the one called meTestVideo. In your PlayVideo() method you want to reference your existing MediaElement, something like this:

private async void PlayVideo()
    {
        string VideoUrl = "http://www.youtube.com/watch?v=2rJwYN_SmOU";
        var url = await YouTube.GetVideoUriAsync(VideoUrl, YouTubeQuality.Quality360P);
        meTestVideo.Source = url.Uri;
    }

这篇关于XAML 视频插入未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆