Play Youtube video using video url in - ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

Play Youtube video using video url in

In this article I am going to explain how to play YouTube video using video url in web application


I want to play the youtube video in application. To play the video the simply enter the particular youtube video url.

Add a webform to application. Add the below given HTML markup to webform.

HTML Markup:
   <td>Enter Youtube Video URL :</td>
   <td> <asp:TextBox ID="txturl" runat="server" Width="450px"></asp:TextBox></td>
   <td> <asp:Button ID="btnsubmit"
            runat="server" Text="Play"/></td>
   <td colspan="3" id="video" runat="server"></td>

On button click write the below given code

C# code:
protected void btnsubmit_Click(object sender, EventArgs e)
        string VideoUrl = txturl.Text;
        string vCode = VideoUrl.Substring(VideoUrl.LastIndexOf("v=") + 2);
        if (vCode.Contains("&"))
            vCode = vCode.Substring(0, vCode.LastIndexOf("&"));
        string frame = @"<object width='{0}' height='{1}' data='{2}&autoplay=1' codetype='application/x-shockwave-flash'>
  &ltparam name='movie' value='{2}&autoplay=1' ></param></object>";       
        string fWidth = "600px";
        string fHeight = "500px";
        video.InnerHtml = String.Format(frame, fWidth, fHeight, vCode);

VB code:
Protected Sub btnsubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
        Dim VideoUrl As String = txturl.Text
        Dim vCode As String = VideoUrl.Substring(VideoUrl.LastIndexOf("v=") + 2)
        If vCode.Contains("&") Then
            vCode = vCode.Substring(0, vCode.LastIndexOf("&"))
        End If
        Dim frame As String = "<object width='{0}' height='{1}' data='{2}&autoplay=1' codetype='application/x-shockwave-flash'>" & vbCr & vbLf & "  &ltparam name='movie' value='{2}&autoplay=1' ></param></object>"
        Dim fWidth As String = "600px"
        Dim fHeight As String = "500px"
        video.InnerHtml = [String].Format(frame, fWidth, fHeight, vCode)
    End Sub

Build the application and run it. To test the code enter the any youtube video URL.

Play Youtube video using video url in

  In this article we have learn to how to play youtube video using video url in I hope you enjoyed this article. 

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.