Louay Sleman
Louay Sleman

Reputation: 2116

How to play youtube from rss on UWP

I'm using an appstudio code and when I get the post from my wordpress I can view pictures and text and everything fine but when I try to play the youtube video It's open Microsoft edge to show me the video Can anyone help me Here's the Html Block code

                        <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"/>

and the Html Style:

    <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>

Upvotes: 2

Views: 231

Answers (1)

Louay Sleman
Louay Sleman

Reputation: 2116

After 2 weeks from searching and editing codes finally I've fix it ! to resolve this you have to edit the AppStudio.Uwp dll file and I'll show you how:

First you havr to install the AppStudio.Uwp source code from here

after that you must remove the AppStudio.Uwp Nuget package from your project and after that open the AppStudio.Uwp source code with visual studio and go to this path: AppStudio.Uwp\Controls\HtmlBlock\Writers

and open this file: IFrameVideoWriter.cs

after that replace the DependencyObject GetControl with this code:

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

when you done build the file and import the dll file to your project and you done! Hope this will help anyone search for it I've take two weeks to solve it by my self !

Upvotes: 5

Related Questions