YouTube Viewer ![Visual Basic]

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
4 posts Page 1 of 1
Contributors
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

YouTube Viewer ![Visual Basic]
Axel
Just a very basic YouTube Viewer tutorial :D
you require Adobe flash player( wich most users have )
lets start with making a project
Image
then right click your toolbox and click "Choose Items"
Image
After the "Choose Toolbox items " box is loaded , go to COM components and search for "Shockwave flash object" , check it and click "ok".
Image
ok now the ShockWave flash object should be in our toolbox. Add a Shockwave flash object to your form and name it "swf" , also add a textbox and name it "txt"
Image
after you renamed them just add some code.

declare your final url ( that is the url that gives you the ability to play the movie in a swf object)
Code: Select all
   Dim urlfinal As String

add a subroutine that converts the original youtube URL to the embed url (for example : "http://www.youtube.com/watch?v=tWkOURXLO8c") and add a ByVal thingy so your app knows what the original url is.
Code: Select all
 Sub GenerateURL(ByVal YoURL As String)
Now lets make a Uri to check if the host is Youtube and not Metacafe or something
Code: Select all
 Dim tube As New Uri(YoURL)
Check if the host != youtube
Code: Select all
        If Not tube.Host = "www.youtube.com" Then
             MsgBox("The url is not valid")
But if the url is valid , continue converting.
Code: Select all
Else
                      If YoURL.Contains("watch?v=") Then
                              'Make the url an embed url by replacing some things.
                              urlfinal = YoURL.Replace("watch?v=", "v/")
            End If
        End If
Now add something to let your swf know what it needs to play
Code: Select all
swf.Movie = urlfinal
and ofcourse , don't forget to close the sub
Code: Select all
End Sub
now search for your keydown handler of your textbox and let it continue when enter is pressed
Code: Select all
 Private Sub txt_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt.KeyDown
        'When typing and pressing Enter , the youtube video will appear/generate
        If e.KeyCode = Keys.Enter Then
            GenerateURL(txt.Text)
        End If
    End Sub

or the complete code with notes :
Code: Select all
Public Class Form1
    'After converting this will be your final URL
    Dim urlfinal As String
    Sub GenerateURL(ByVal YoURL As String)
        'Command to generate the url
        Dim tube As New Uri(YoURL)
        'Check if the url is from youtube
        If Not tube.Host = "www.youtube.com" Then
            'Give an error
            MsgBox("The url is not valid")
        Else
            'if the url is valid , continue converting
            If YoURL.Contains("watch?v=") Then
                'Convert the original URL to a embed URL
                urlfinal = YoURL.Replace("watch?v=", "v/")
            End If
        End If
        ' Show the embed Movie
        swf.Movie = urlfinal
        'Just for some extra , show the finalURL in your form
        Me.Text = urlfinal
    End Sub
    Private Sub txt_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt.KeyDown
        'When typing and pressing Enter , the youtube video will appear/generate
        If e.KeyCode = Keys.Enter Then
            GenerateURL(txt.Text)
        End If
    End Sub
End Class
Final :
Image

Thats it donate by downloading my project + rep me up if u like it please cooll;
YouTube Viewer.zip
You do not have the required permissions to view the files attached to this post.
http://vagex.com/?ref=25000
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

Re: YouTube Viewer ![Visual Basic]
Lewis
This has been posted before.. But good work :DDD
Image
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: YouTube Viewer ![Visual Basic]
Axel
Lewis wrote:
This has been posted before.. But good work :DDD
but everyone uses a browser wich is bad...
http://vagex.com/?ref=25000
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1892
Joined: Wed Dec 16, 2009 9:56 pm

Re: YouTube Viewer ![Visual Basic]
zachman61
yea i made one where it was a media player
yours is still better
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
4 posts Page 1 of 1
Return to “Tutorials”