如何在 UWP 上播放来自 rss 的 youtube

How to play youtube from rss on UWP

我正在使用 appstudio 代码,当我从 wordpress 获取 post 时,我可以查看图片和文本,一切正常,但是当我尝试播放 youtube 视频时,它打开了 Microsoft edge 向我展示视频 谁能帮我 这是 Html 块代码

                        <was_controls:HtmlBlock
                        Grid.Row="2"
                        FlowDirection="RightToLeft"
                        Margin="24,10,24,130"
                        Style="{StaticResource HtmlPersonalStyle}"
                        FontSize="{Binding ViewModel.FontSize, ElementName=root}"
                        Source="{Binding ViewModel.SelectedItem.Description}" Grid.RowSpan="2"/>

和 Html 样式:

    <Style TargetType="was:HtmlBlock" x:Key="HtmlPersonalStyle">
    <Setter Property="Foreground" Value="{ThemeResource ApplicationHeaderForegroundThemeBrush}"/>
    <Setter Property="DocumentStyle">
        <Setter.Value>
            <was:DocumentStyle>
                <was:DocumentStyle.Channel9>
                    <was:ImageStyle HorizontalAlignment="Center"/>
                </was:DocumentStyle.Channel9>
                <was:DocumentStyle.Img>
                    <was:ImageStyle HorizontalAlignment="Center"/>
                </was:DocumentStyle.Img>
                <was:DocumentStyle.P>
                    <was:ParagraphStyle Margin="0,24,0,24"  />
                </was:DocumentStyle.P>

                <was:DocumentStyle.Code>
                    <was:TextStyle Foreground="{StaticResource NavigationPaneButton}" FontWeight="Bold" />
                </was:DocumentStyle.Code>
                <was:DocumentStyle.FigCaption>
                    <was:ParagraphStyle Foreground="SaddleBrown"/>
                </was:DocumentStyle.FigCaption>
                <was:DocumentStyle.Ul>
                    <was:ContainerStyle Margin="0,24,0,24" />
                </was:DocumentStyle.Ul>
                <was:DocumentStyle.H1>
                    <was:ParagraphStyle FontSizeRatio="2" />
                </was:DocumentStyle.H1>
                <was:DocumentStyle.H2>
                    <was:ParagraphStyle />
                </was:DocumentStyle.H2>
                <was:DocumentStyle.Li>
                    <was:ListStyle FontWeight="Bold" Margin="10,0,0,0"/>
                </was:DocumentStyle.Li>
                <was:DocumentStyle.Span>
                    <was:TextStyle Foreground="#FF104F83" FontStyle="Normal"/>
                </was:DocumentStyle.Span>
                <was:DocumentStyle.A>
                    <was:TextStyle Foreground="{StaticResource NavigationPaneButton}" FontWeight="Bold"/>
                </was:DocumentStyle.A>
                <was:DocumentStyle.Cite>
                    <was:TextStyle Foreground="{StaticResource NavigationPaneButton}" FontWeight="Bold"/>
                </was:DocumentStyle.Cite>
                <was:DocumentStyle.YouTube>
                    <was:ImageStyle HorizontalAlignment="Center"/>
                </was:DocumentStyle.YouTube>
                <was:DocumentStyle.Figure>
                    <was:ContainerStyle Margin="0,24,0,24"/>
                </was:DocumentStyle.Figure>
                <was:DocumentStyle.Time>
                    <was:TextStyle FontSizeRatio="0.9" FontStyle="Italic" />
                </was:DocumentStyle.Time>
            </was:DocumentStyle>
        </Setter.Value>
    </Setter>
</Style>

经过 2 周的搜索和编辑代码,我终于修复了它! 要解决此问题,您必须编辑 AppStudio.Uwp dll 文件,我将向您展示如何:

首先,您必须安装来自 here

的 AppStudio.Uwp 源代码

之后,您必须从项目中删除 AppStudio.Uwp Nuget 包 然后使用 visual studio 打开 AppStudio.Uwp 源代码并转到此路径:AppStudio.Uwp\Controls\HtmlBlock\Writers

并打开此文件:IFrameVideoWriter.cs

之后用此代码替换 DependencyObject GetControl

 public override DependencyObject GetControl(HtmlFragment fragment)
    {
        var node = fragment as HtmlNode;
        MediaElement play = new MediaElement();
        if (node != null)
        {
            Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            localSettings.Values["itson"] = null;
            string src = GetIframeSrc(node).ToString();
            string id = GetVideoId(src);
            string check = "";
            var grid = new Grid
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
        };

            grid.Tapped += async (sender, e) =>
            {
                play.HorizontalAlignment = HorizontalAlignment.Stretch;
                if (localSettings.Values["itson"] == null || id != check)
                {
                        var url = await YouTube.GetVideoUriAsync(id, YouTubeQuality.Quality360P);
                        play.Source = url.Uri;
                        localSettings.Values["qv"] = "360";

                    }
                    check = id;
                    play.AreTransportControlsEnabled = true;
                    localSettings.Values["itson"] = "true";
                    play.Play();

                }
            };

            grid.PointerEntered += (sender, e) =>
            {
                Window.Current.CoreWindow.PointerCursor = _handCursor;
            };
            grid.PointerExited += (sender, e) =>
            {
                Window.Current.CoreWindow.PointerCursor = _arrowCursor;
            };

            AddColumn(grid);
            AddColumn(grid);
            AddColumn(grid);

            var screenShot = GetImageControl((i) => SetScreenshot(i, node));

            Grid.SetColumn(screenShot, 0);
            Grid.SetColumnSpan(screenShot, 3);
            grid.Children.Add(screenShot);

            var player = GetImageControl((i) => i.Source = GetPlayerImage());
            Grid.SetColumn(player, 1);
            grid.Children.Add(player);
            Grid.SetColumn(play, 0);
            Grid.SetColumnSpan(play, 4);
            grid.Children.Add(play);
            return grid;
        }

        return null;
    }

当您完成构建文件并将 dll 文件导入您的项目时,您就完成了! 希望这会帮助任何人搜索它我花了两周时间自己解决它!