Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Knowledge Base > Code Library > Some answers. ASP and media player control.


Reply
 
Thread Tools Display Modes
  #1  
Old 02-16-2009, 10:23 AM
DrPunk's Avatar
DrPunk DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default 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.
__________________
There are no computers in heaven!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->