Wednesday, October 14, 2015

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. 

No comments:

Post a Comment