bmahler was on the right track. You can simply load up JUST the html of the object you want to view (in this case a flash video). You can adjust the height and width prior to loading the HTML so the video can render at whatever size you want.
In this example code, it assumes there is just a webbrowser control on the form called Webbrowser1. It grabs the height and width of the browser control (which by default is docked).
So just start a new project, add a webbrowser control to the form, then go into the code and erase any code in there, and paste this:
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'HTML STRING WE WANT TO LOAD TO BROWSER CONTROL
'NOTICE THE DOUBLE "" AROUND ALL THE PARTS INSIDE
'THE STRING THAT REQUIRE SINGLE "
Dim HTMLString As String = "<html><body>" & _
"<object width=""{width}"" height=""{height}"">" & _
"<param name=""movie"" value=""http://www.youtube.com/v/k66epna2Sss&hl=en""></param>" & _
"<embed src=""http://www.youtube.com/v/k66epna2Sss&hl=en"" type=""application/x-shockwave-flash"" width=""{width}"" height=""{height}"">" & _
"</embed></object></body></html>"
'WE REPLACE THE WIDTH AND HEIGHT CONSTANTS IN THE ABOVE STRING
'WITH THE PHYSICAL CURRENT SIZE OF THE BROWSER CONTROL IN THE FORM
HTMLString = HTMLString.Replace("{width}", WebBrowser1.Width.ToString)
HTMLString = HTMLString.Replace("{height}", WebBrowser1.Height.ToString)
'LOAD THE HTML INTO THE BROWSER
WebBrowser1.DocumentText = HTMLString
End Sub
'BROWSER SIZE CHANGED (BECAUSE FORM SIZE CHANGED)
Private Sub WebBrowser1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser1.SizeChanged
'MAKE SURE DOCUMENT IS LOADED BEFORE WE DO ANYTHING
'(BECAUSE THIS EVENT FIRES WHEN FORM IS CREATED)
If WebBrowser1.Document Is Nothing Then Return
'GRAB THE EMBED ELEMENT FROM THE HTML
Dim objectCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("embed")
'MAKE SURE WE GOT AT LEAST 1 EMBED ELEMENT RETURNED
'IN THE CASE OF THIS EXAMPLE, THE COUNT SHOULD ALWAYS BE 1
If (objectCollection IsNot Nothing) AndAlso _
(objectCollection.Count <> 0) Then
'GRAB THE SINGLE <EMBED> ELEMENT
Dim movieElement As HtmlElement = objectCollection.Item(0)
'ADJUST HEIGHT AND WIDTH ACCORDING TO NEW SIZE
movieElement.SetAttribute("width", WebBrowser1.Width.ToString)
movieElement.SetAttribute("height", WebBrowser1.Height.ToString)
End If
End Sub
End Class
As for not showing the shortcuts on mouse over, I don't know how you could prevent that. I don't think there is a direct way, short of something that would be considered a hack. I have 1 idea how you could do it, so I will let you know if I think it is something that works properly.
I don't think there is a direct way, short of something that would be considered a hack.
What I'd like to do is control the embedded youtube video via my own form buttons.
The webbrowser would become something like a picturebox, ie: display only without allowing the user to click the webbrowser and go to other urls, links from there. I guess what we're doing is creating our own youtube/flv player on a form.
come on now, we're dealing with a webbrowser here.
PLAY is easy. STOP is easy. REW is webbrowser reload. There is no FF
why is play easy? its easy the first time, but what if the user wanted to pause and then continue? If i remember rightly, the youtube video player is just a flash object and I dont know how you can interact with flash via VB.NET (although there is thread on this forum on the first page asking the question about VB with Flash so maybe you could take a look there)
Oh and REW isnt webbrowser reload because thats just stopping the whole video and playing it from the start again, what if it was a 20 minute video and the user just wanted to go back 1 minute..
I don't think there is a direct way, short of something that would be considered a hack. I have 1 idea how you could do it, so I will let you know if I think it is something that works properly.
How about subclassing the HWnd ?
Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim s As SubclassHWND = New SubclassHWND()
s.AssignHandle(Me.Webbrowser1.Handle)
' Now s should be listening to the webbrowser's messages.
End Sub
Code:
Public Class SubclassHWND
Inherits NativeWindow
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_LBUTTONDBLCLK As Integer = &H203
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
' do whatever custom processing you need for
Select Case m.Msg
Case WM_LBUTTONDOWN
' Disable mousedown/click
Case WM_LBUTTONDBLCLK
' Disable double click
Case Else
'It is important to pass unhandled messages back to the default message handler.
MyBase.WndProc(m)
End Select
End Sub
End Class
why is play easy? its easy the first time, but what if the user wanted to pause and then continue? If i remember rightly, the youtube video player is just a flash object and I dont know how you can interact with flash via VB.NET (although there is thread on this forum on the first page asking the question about VB with Flash so maybe you could take a look there)
Oh and REW isnt webbrowser reload because thats just stopping the whole video and playing it from the start again, what if it was a 20 minute video and the user just wanted to go back 1 minute..
We can't do the impossible. So, REW is rewind completely. Stop is STOP completely. Play is play from beginning. I think we agree on this.
We can't do the impossible. So, REW is rewind completely. Stop is STOP completely. Play is play from beginning. I think we agree on this.
why is that impossible :S You can rewind a video on youtube by dragging the timeline blob back a bit so if you can find out how to interact with the youtube flash player then you can do the same thing programmatically.
Well.... I still think its going to be really hard but I'm just saying if you could do play/pause then rewind is going to require the same method.
Have you looked at this thread yet? http://www.vbforums.com/showthread.php?t=523975
For the most control, you would want to write your own Flash Player and use the YouTube APIs to feed it. Doing everything via a web browser will limit you.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
You are not going to find a procedure that says that. Its a complete project. You will fine the YouTube APIs being referenced and that should show/direct you what all is needed.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Hi, i've been thinking about this; is it possible to just use a normal webbrowser object but play audio or/and video on a normal player like media player object then use its controls like play,pause e.t.c (buffer load the video or something ). Am trying to play youtube videos too
dex3844, you should create your own thread instead of digging up a 4 year old thread.
But to answer your question... if you want to play YouTube videos on your form, then you can use the ShockWave Flash Player (assuming the uploader has enabled embedding). You don't have to mess around with the WebBrowser control.
In VS2010 right-click somewhere on your Toolbox and select "Choose Items...".
Go to the "COM Components" tab, tick "ShockWave Flash Object" and click on "OK".
You now have "ShockWave Flash Object" in your Toolbox and drag it onto the form.