Search code examples
c#xamlwindows-store-appsyoutube-apiyoutube-data-api

How to playback videos with YouTube API v3 in Windows Store apps?


I created a Windows Store app with C# and XAML to playback YouTube videos but since YouTube shutdown their Data API v2, my app fails playing videos.

What should I do to play videos with Data API v3?

I have been using the Microsoft Player Framework with this code:

XAML

<mmppf:MediaPlayer 
  x:Name="videoElement" 
  VerticalAlignment="Top"
  Grid.Column="1" 
  Width="Auto" 
  Height="Auto" 
  IsFullScreenVisible="True" 
  IsFullScreenChanged="videoElement_IsFullScreenChanged" 
  MediaFailed="videoElement_MediaFailed" 
/>

C#

var url = await YouTube.GetVideoUriAsync("aMbM7dSCHEk", YouTubeQuality.Quality1080P);
videoFile = url.Uri;

if (videoFile != null) videoElement.Source = videoFile;

Solution

  • It was easier than I thought. I had to update the MyToolkit reference of my project. In addition I had to add MyToolkit.Extended to make use of the YouTube classes.

    packages.config

    <packages>
      <package id="MyToolkit" version="2.3.30.0" targetFramework="win81" />
      <package id="MyToolkit.Extended" version="2.3.30.0" targetFramework="win81" />
    </packages>