How to play an Online Video/Audio inside WinRT MediaElement object?

(SAM) #1

Is it possible to play an online video/audio media file inside a WinRT MediaElement in a UWP App.

i tried to play a youtube video using this XAML code below but it fails:

        <RowDefinition />
        <RowDefinition Height="30" />
    <MediaElement x:Name="_MediaElement" 
                    AutoPlay="False" />
    <StackPanel Grid.Row="1" Orientation="Horizontal" 
                HorizontalAlignment="Center" VerticalAlignment="Center">
        <Button Content="Play" Click="Play_Click"/>
        <Button Content="Pause" Click="Pause_Click"/>
        <Button Content="Stop" Click="Stop_Click" />

The XAML above didn’t work and didn’t play the video i tried to play the video manually from the code behind using this code:

public MainWindow()
    Uri uri = new Uri("");
    _MediaElement.Source = uri;

But that didn’t work as well, please Help.

(isoftech) #2

The MediaElement in WinRT can play online media files automatically, but the problem in your XAML and code is that you are not giving it a path/uri to a media file but instead you are giving it a path to the youtube webpage that hosts the video frame.

  • This is not the media file path:
    It’s only a Web page URL.

  • To fix that issue you have two options:

  1. Use a WebView and display the Web Page within it. that url above will work for a WebView Control.

  2. Or Get the real Video Url and in case of Youtube Media files i don’t think that would be an easy task.