Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   Code Library (http://www.xtremevbtalk.com/code-library/)
-   -   Some answers. ASP and media player control. (http://www.xtremevbtalk.com/code-library/304669-answers-asp-media-player-control.html)

DrPunk 02-16-2009 10:23 AM

Some answers. ASP and media player control.
 
Hello,

Not been round these parts for a while. Been working on a project and have had to answer a few problems which I was struggling to find the answers for on the internet and seeing as I'm a nice fellow who likes to share I thought I'd pop back here and post it all for other people to use.

I don't know if someone would be nice enough to sort them out so they are easier to find, I'm not really too sure where to put any of it. So I'm gonna dump it here and we'll see what happens.

1. Scrolling the webbrowser control.

I'm working with pretty much a purely HTML site so I'm not too sure yet what might have to change for other sites. But anyway...

I'd tried a few API suggestions off the internet and nothing was working. I couldn't even get GetScrollInfo to work, let alone SetScrollInfo.

I was able to get the window to scroll by calling the ScrollTo method of the browser.Document.Window but I was struggling to get the current position of the scrollbar.

After checking all the HTMLelements from browser.Document.All I noticed that the HTMLelement with the tag HTML had the scrolltop property that I had set.

Therefore, to scroll the webbrowser control, let's say 20 pixels...

Code:

Dim y as integer = browser.Document.GetElementsByTagName("HTML").Item(0).ScrollTop
y += 20
browser.Document.Window.ScrollTo(0, y)

2. Stop debug errors in webbrowser

The next problem I was having was with script errors showing up in the control, even though all the settings within Internet options suggested these errors wouldn't be shown.

What we need to do to catch these errors is to trap errors thrown by the Window of the Document of the webbrowser control.

Obviously the window has to be set, so the best place to put the handler is in the document complete event.

Code:

Private Sub DocumentComplete(byval sender as Object, byval e as WebbrowserDocumentCompletedEventArgs)

    If browser.Document.Window IsNot Nothing then
        AddHandler browser.Document.Window.Error, Address of PageError
    Endif

End Sub

' And the sub to catch the event
Private Sub PageError(byval sender as object, byal e as HtmlElementErrorEventArgs)

    ' You can do whatever you want, display the message yourself, but to stop
    ' the browser from showing the error just set handled to true
    e.handled = True
End Sub

You also need to remove the handler, and I'm doing this whenever the user is navigating to a new page (i.e. in the navigating event if I'm allowing the link). Not sure if that's the best place, but it works.

3. Fullscreen Windows Media Player control

I was having problems with fullscreen using the windows media control. Seen a lot of other people have the same problem. It's the critical error when you try to set fullscreen after it's played one video (it returns to not fullscreen after playing one video).

The simple answer to this is to only set fullscreen when it's playing.

The best thing to do is to stop autoplay, otherwise you sometimes miss the start of the clip.
Code:

MediaPlayerControl.Settings.AutoStart = False
You set the url of the clip you want to play and tell the media player to play it
Code:

MediaPlayerControl.Url = Whatever
MediaPlayerControl.ctlControl.Play

Then, you catch the playing event in the playstate changed event of the control and set fullscreen
Code:

Private Sub PlayStateChanged(byval sender as Object, byval e as _WMPOCXEvents_PlaystateChangeEvent)

    Select Case MediaPlayerControl.playstate
        Case WMPPlaystate.wmppsPlaying
            MediaPlayerControl.Fullscreen = True
    End Select
End Sub

I also find it useful to hide the media player when it has stopped to try and stop the user seeing it resize back to normal. The fullscreen sets it visible when it's hidden so that takes care of that too.

I'm sorry for any errors in the code, I've typed them out rather than copied them.

Also, apologies again for just dumping this here, but hopefully it can find a good home.

Cheers.


All times are GMT -6. The time now is 01:23 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.