Sunday, 13 October 2013

How to play youtube videos in winrt apps?



Hi today i would like to explain on How to play youtube videos in winrt apps?? actually for winrt apps we have media tag to play the video files but this media tag will accept only the playable extention files onlly... so if user want to give the youtube url from this folowing method we can play the youtube url's you need to download the mytoolkit.dll from opensource it will available in out side.

"public static readonly Regex YoutubeVideoRegex = new Regex(@"^(?:https?\:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v\=))([\w-]{10,12})(?:$|\&|\?\#).*", RegexOptions.IgnoreCase);"

        public static string GetYouTubeID(string youTubeUrl)
        {
            Match youtubeMatch = YoutubeVideoRegex.Match(youTubeUrl);
            string id = string.Empty;
            if (youtubeMatch.Success)
                id = youtubeMatch.Groups[1].Value;
            return id;
        }

 public async void GetYoutubeUri(string Externalurl)
        {
            var url = await YouTube.GetVideoUriAsync(videoId, YouTubeQuality.Quality1080P);
            var YoutubePlayer = new MediaElement();
            VideoSource.Source = url.Uri;        
        }

from the above post you will get the ID for your youtube url then by that id passing to the "YouTubeQuality" which was came from the "mytoolkit.dll" which we downloaded earlier. then by sending the videoID we will get the URI... after that just you need to bind the URI to media tag. it will automatically returns play the video in winrt apps.


No comments:

Post a Comment