Friday 4 October 2013

Play Youtube video with URL in C#.NET

Copy and paste this code on C# code file


                    string youtubeUrl = "http://www.youtube.com/watch?v=6rpZnBfG6YE";

                    string vCode = youtubeUrl.Substring(youtubeUrl.LastIndexOf("v=") + 2);
                    if (vCode.Contains("&"))
                        vCode = vCode.Substring(0, vCode.LastIndexOf("&"));

                    string sHtml = @"<object width='{0}' height='{0}' data='http://www.youtube.com/v/{2}&autoplay=0' codetype='application/x-shockwave-flash'>
                           &ltparam name='movie' value='http://www.youtube.com/v/{2}&autoplay=0'></param></object>";
                    //define frame size
                    string sWidth = "200px";
                    string sHeight = "100px";

                    video.GroupingText = String.Format(sHtml, sWidth, sHeight, vCode);

where video is the Id of Div/Panel

               

No comments:

Post a Comment