none
Playing YouTube videos using MediaElement in Metro Application

    Question

  • Can you play YouTube videos using MediaElement in Metro Application?
    I don't want to use webView because that would need user to turn on HTML5 support on youtube to serve HTML5 version of videos.

    There's no place without shadow.

    Friday, July 20, 2012 3:11 PM

Answers

  • This was very close to solving my problem already.
    But I wanted to use MediaElement.

    I found out that there's my http://mytoolkit.codeplex.com/ which has nice YouTube class which you can use to get the MP4-link of the video.

    Using that solved my problem.

    using MyToolkit.Multimedia;
    var url = await YouTube.GetVideoUriAsync(youtubeid, YouTubeQuality.Quality1080P);
    var YoutubePlayer = new MediaElement();
    YoutubePlayer.Source = url.Uri;



    Teemu Tapanila Microsoft Student Partner

    Sunday, July 29, 2012 10:53 AM

All replies

  • You *can* show classic (Flash) YouTube videos in a WebView:

                string htmlFragment =
                   "<iframe src='http://www.youtube.com/embed/{YouMovieIdHere}' width='560' height='315' />";
    
                this.YouTubeWebView.NavigateToString(htmlFragment);

    You just have to find a way to hide the border of the iFrame...

    Friday, July 20, 2012 4:19 PM
  • Thanks for that information. I thought you can't play flash in webview.
    But is there anyway to pause/play the video from C# side if you do it that way?
    Also at least for me the fullscreen playing of the video didn't work.

    Teemu Tapanila Microsoft Student Partner



    Saturday, July 21, 2012 9:29 AM
  • There is no flash in Webview.  You can force HTML5 youtube by using ?html5=1 in the source url.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    Wednesday, July 25, 2012 7:07 PM
  • This was very close to solving my problem already.
    But I wanted to use MediaElement.

    I found out that there's my http://mytoolkit.codeplex.com/ which has nice YouTube class which you can use to get the MP4-link of the video.

    Using that solved my problem.

    using MyToolkit.Multimedia;
    var url = await YouTube.GetVideoUriAsync(youtubeid, YouTubeQuality.Quality1080P);
    var YoutubePlayer = new MediaElement();
    YoutubePlayer.Source = url.Uri;



    Teemu Tapanila Microsoft Student Partner

    Sunday, July 29, 2012 10:53 AM
  • I've been looking into this a bit as well. And although the YouTube class from MyToolkit, might technically solve the problem, I'm not sure it's a good idea. Looking at the terms and conditions (https://developers.google.com/youtube/terms) of YouTube, it states in part II Prohibitions, point 10. "access any portion of any YouTube audiovisual content by any means other than use of a YouTube player or other video player expressly authorized by YouTube;"

    So as far as I understand it, that means you're not allowed to play a YouTube video in your own mediaelement control. Or?

    So although possible, I'm a bit dubious, if you're building a little hobby project app for yourself, that's one thing but building a "real" app, say for a client.. Not so sure I'd want to use this solution.. 

    /Ola 

    Thursday, June 20, 2013 12:35 PM
  • Hi, I tried to use this code but it doesn't work as well...the only result is black screen can someone help me?
    var url = await YouTube.GetVideoUriAsync("tYrND5hMY3A", YouTubeQuality.Quality1080P);
                var YoutubePlayer = new MediaElement();
                YoutubePlayer.Source = url.Uri;

    Thursday, November 21, 2013 9:03 AM
  • I think the problem is that you are not calling YoutubePlayer.Play() in your code.
    Wednesday, December 11, 2013 3:22 AM
  • I got the following error when i use this code,

    "An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll"

    Wednesday, February 26, 2014 6:06 AM
  • Can any one help regarding this issue
    Wednesday, February 26, 2014 6:07 AM