Sign in to follow this  
Followers 0
CYCho

WMPlayer.ocx embedded in IE

7 posts in this topic

#1 ·  Posted (edited)

I wrote the follwoing program to play video clips residing in web pages. I have a list of URLs of these video clips and want to play them in succession, sometimes skipping to the next one by clicking the window's close button or by clicking the "Stop" button on the player. I want also to see the current position of the media relative to the duration.

As you can see, I used graphical means to realize this because I don't know how to get such information programatically from the ActiveX. I used Internet Explorer foramt because I cannot adjust the image size if I embed the ocx directly in a gui.

So my question is twofold. One, can I ajdust the image size of WMPlayer ActiveX embedded in a gui? If not, can I read the current position and status of the media loaded in an IE object?

Thank you in advance.

CYCho

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

Dim $clips[2]
$clips[0] = "http://enka2.netorage.com:9711/harddisk/user/lyk36/musicmvz/0-christmascarol.wmv"
$clips[1] = "http://www.clubbalcony.com/upload/culture/yong(2).wmv"

For $x = 0 To 1
    PlayVideo($clips[$x])
Next

Func PlayVideo($song)
    Dim $oPlayer, $gVideo, $oIE
    $oPlayer = ObjCreate("wmplayer.ocx")
    $oPlayer.url = $song
    $time1 = TimerInit()
    While 1
        If $oPlayer.playState() = 3 Then
            $width = $oPlayer.currentMedia.imageSourceWidth
            $height = $oPlayer.currentMedia.imageSourceHeight
            $len = Int($oPlayer.currentMedia.Duration())
            $oPlayer.Close()
            ExitLoop
        EndIf
        If TimerDiff($time1) > 5000 Then
            $oPlayer.Close()
            Return
        EndIf
        Sleep(10)
    WEnd
    $len1 = StringRight(100+Int($len/60), 2) & ":" & StringRight(100+Mod(Int($len), 60), 2)
    If $width < 600 Then
        $ratio = 600/$width
        $width = Int($width * $ratio + 0.5)
        $height = Int($height * $ratio + 0.5)
    EndIf

    $oIE = ObjCreate("Shell.Explorer.2")
    $gVideo = GUICreate("zPlayer Video Control", $width, $height-1, @DesktopWidth-$width-6, 0, $GUI_SS_DEFAULT_GUI, $WS_EX_TOPMOST)
    GUICtrlCreateObj($oIE, 0, 0, $width, $height)

    $oIE.Navigate("about:blank")
    $html = '' _
    & @CR & '<body style="margin:0; padding:0">' _
    & @CR & '<embed src="' & $song & '" width=' & $width  & ' height=' & $height & ' autostart=true volume=0 showcontrols=true></body>'
    $oIE.document.write($html)
    $oIE.document.close()
    $oIE.document.execCommand("Refresh")
    $oIE.document.body.scroll = "no"
    $oIE.document.body.style.border = 0
    GUISetState(@SW_SHOW, $gVideo)

    $time1 = TimerInit()
    While 1
        $vmsg = GUIGetMsg(1)
        Dim $vxy
        If $vmsg[0] = $GUI_EVENT_CLOSE Then
            ExitLoop
        EndIf
        $vxy = WinGetPos($gVideo)
        If PixelGetColor($vxy[0]+32, $vxy[1]+$vxy[3]-16, $gVideo) = 1914445 And PixelGetColor($vxy[0]+58, $vxy[1]+$vxy[3]-16, $gVideo) = 10331306 Then
    ; I graphically read the colors of player's "Play" and "Stop" buttons to see if the media has stopped
            ExitLoop 
        EndIf
        If TimerDiff($time1) > 1000 Then
            $time1 = TimerInit()
            $ty = $vxy[1]+$vxy[3]-36
            $tx1 = $vxy[0]+21
            $tx2 = $vxy[0]+$vxy[2]-31
            $txy = PixelSearch($tx1, $ty, $tx2, $ty, 13359079)
    ; I graphically read the position of tracker to understand the current position
            If @error <> 1 Then
                $pct = Int(($txy[0]-$tx1)/($tx2-$tx1)*$len)
                $len2 = StringRight(100+Int($pct/60), 2) & ":" & StringRight(100+Mod(Int($pct), 60), 2)
                WinSetTitle($gVideo, "", "zPlayer Video Control - " & $len2 & "/" & $len1)
            EndIf
        EndIf
        Sleep(40)
    Wend
    $oIE.Stop
    GUISetState(@SW_HIDE, $gVideo)
EndFunc
Edited by CYCho

Share this post


Link to post
Share on other sites



The above progam runs OK in my desktop with Windows Media Player 9 and Windows XP. I realize that the program may not work in other versions of Media Player or OS. That's another reason I should get the inforamtion by non-graphical means.

Share this post


Link to post
Share on other sites

Hallo Cysco

To resize wmp...ocx directly in an intuition is not posible as this components is ment to be standalone or embeded into html and has a self configurated sizeing implimented

If you want to control the size you has to embed the wmp into a form - like in VB

$oForm = ObjCreate("Forms.Form.1"); this is a old form
$oButton = $oForm.Add("WMPlayer.OCX.7","WindowsMediaPlayer1",1)
With $oButton
    .caption = "Medie player"
    .Left = 10
    .Top = 10
    .Height = 70
    .Width = 220
EndWith
; Use events to control/read data

In this manner you can control the ocx directly without IE - check MSWord to look for forms

kjactive :)

Share this post


Link to post
Share on other sites

Hi kjactive, thank you for your attention, but I don't understand your point. Maybe my knowledge in AutoIt is too short. Please elaborate a little more.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hallo CYCho

I did fidle around with the same trouble ones, years ago - I have a script but it woun't run on latest autoit3 revision, and some components like the form ( I think it's FM.dll or something like that is very old and bugy ) but the script should give you a hint on using forms to embed other components like one do in MSWord or VB

; =======================================================================
; Au3ComDialog 1.0.0 by Kåre Johansson 30.1.06
; arguments no / return no
; =======================================================================

#include <GUIConstants.au3>
Opt('GUIResizeMode',802); no resize etc.
HotKeySet("{F1}", 'Preview'); toggle the preview mode on / off
HotKeySet("{F2}", 'ClearToNew'); test
HotKeySet("{F4}", 'SaveScript')
HotKeySet("{F5}", 'ToggleToolBox')
;HKEY_CLASSES_ROOT\?
; http://www.myplugins.info/guids/typeinfo/typeinfo.php?clsid= ( and then CLSID )
;http://www.myplugins.info/guids/guid.php?guid=8b
;http://www.myplugins.info/guids/guid.php?guid=97
;http://support.microsoft.com/default.aspx?scid=kb;en-us;224305
Global Const $Prefs = 'HKEY_CURRENT_USER\software\Au3ComDialog\Prefs',$title = 'Au3ComDialog',$Rev = '1.0',$auther = ' (c)2005 by Kåre Johansson' 
Global $MainW,$dm0,$dm1,$oForm,$oFormEvt,$oMyError,$Status1C,$Status2C,$GUI_ActiveX; intuition variables
Global $ShowTools; application system variables
Global $NewM,$LoadM,$SaveAsM,$PreferencesM,$QuitM,$ToolM,$PreviewM,$ToolBoxM,$AboutM; menus
Global $AboutW,$HomepageC; other intuition
Global $Com = ReadContent(@ScriptDir & '\Templates');readin the contents of the files in templates directory
Global $oForm,$oFormEvt
Global $GUI_Label2,$FullView,$topics,$c
ReadPrefs($Prefs); readin the preferences
FormWindow()
If $com = '' Then; check for templates
    MsgBox(16,"ERROR...","Could not find Component templates")
    $com[0] = 0
Else
    $Com = StringSplit($Com,'|')
EndIf
Global $oButton = $oForm.Add("WMPlayer.OCX.7","WindowsMediaPlayer1",1) ;ok
$oButtonEvt = ObjEvent($oButton,"Button_")
With $oButton
    .caption = "Medie player"
    .Left = 10
    .Top = 8
    .Height = 70
    .Width = 220
EndWith
Global $oButton1 = $oForm.Add("OWC.Spreadsheet.9","OWC.Spreadsheet",1) ;ok
$oButtonEvt1 = ObjEvent($oButton1,"Button1_")
With $oButton1
    .caption = "SpreadSheet"
    .Left = 240
    .Top = 8
    .Height = 220
    .Width = 170
EndWith

For $b = 1 To $com[0]
            For $i= 1 to 100
                $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Classes", $i)
                If $var = '' then ExitLoop
                    $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\" & $var, '')   
            Next
       ;$lines = ReadComLib(@ScriptDir & '\Templates\' & $Com[$b] & '.frm')
Next

While 1
   $msg = GUIGetMsg(1)
   Select
    Case $msg[0] = 0x00000000; catch all uninitiated msgs
    Case $msg[1] = $MainW
        Select
        Case $msg[0] = $GUI_EVENT_RESIZED
            $tmp = WinGetPos($MainW)
            If $dm0[4] <> $tmp[3]-34 Then
            $dm0[1] = $tmp[0]
            $dm0[2] = $tmp[1]
            $dm0[3] = $tmp[2]-8
            $dm0[4] = $tmp[3]-34
            FormWindow()
            If $ShowTools <> 0 Then ToggleToolBox()
            EndIf
        Case $msg[0] = $GUI_EVENT_CLOSE OR $msg[0] = $QuitM
            ExitLoop
        Case $msg[0] = $PreviewM
            Preview()
        Case $msg[0] = $ToolBoxM
            ToggleToolBox()
        Case $msg[0] = $AboutM
            AboutWindow()
        EndSelect
    Case $msg[1] = $AboutW
        Select
        Case $msg[0] = $HomepageC
            Run(@ComSpec & ' /c start http://www.sitecenter.dk/latenight/nss-folder/digitalvision','', @SW_HIDE)
        Case $msg[0] = $GUI_EVENT_CLOSE
            AboutWindow()
        EndSelect
    EndSelect
Wend
Exits()

Func Form_Resize()
    GUICtrlSetData($GUI_Label2,"Button: Single mouseclick!")
EndFunc

;==================================================================
;FormWindow: Open the Formwindow
;argument no / return no
;==================================================================
Func FormWindow()
If WinExists($title & ' ' & $rev & ' ' & $auther) Then
    $oMyError = 0
    $oFormEvt = 0
    $oForm = 0
    GUIDelete($MainW)
EndIf
$oForm = ObjCreate("Forms.Form.1")
$oFormEvt = ObjEvent($oForm,"Form_")
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
With $oForm
    .caption = ""
    .ShowGridDots = 0
    .GridX = 0
    .BorderStyle = 0; 1 border
    .MousePointer = 0; integer 0 - 15
    .ScrollBars = 3; 0 - 3
    .SpecialEffect = 3; 0 - 3
    .PictureSizeMode = 0; 0 clip, 1 strech, 3 Zoom
    .PictureAlignment = 0;  0 top left, 1 top right, 2 center, 3 bottom left, 4 bottom right. 
EndWith
$MainW = GUICreate($title & ' ' & $rev & ' ' & $auther, $dm0[3], $dm0[4], $dm0[1], $dm0[2],BitOr($WS_OVERLAPPEDWINDOW,$WS_VISIBLE,$WS_CLIPSIBLINGS))
$ProjectM = GUICtrlCreateMenu ("Project")
$NewM = GUICtrlCreateMenuitem ("New",$ProjectM)
$LoadM = GUICtrlCreateMenuitem ("Load",$ProjectM)
$SaveM = GUICtrlCreateMenuitem ("Save",$ProjectM)
$SaveAsM = GUICtrlCreateMenuitem ("Save As",$ProjectM)
GUICtrlCreateMenuitem ("",$ProjectM)
$PreferencesM = GUICtrlCreateMenuitem ("Preferences",$ProjectM)
GUICtrlCreateMenuitem ("",$ProjectM)
$QuitM = GUICtrlCreateMenuitem ("Quit",$ProjectM)

$ToolM = GUICtrlCreateMenu ("Tools")
$PreviewM = GUICtrlCreateMenuitem ("Preview",$ToolM)
GUICtrlCreateMenuitem ("",$ToolM)
$CopyM = GUICtrlCreateMenuitem ("Copy",$ToolM)
$PasteM = GUICtrlCreateMenuitem ("Paste",$ToolM)
GUICtrlCreateMenuitem ("",$ToolM)
$CreateM = GUICtrlCreateMenuitem ("Create new library",$ToolM)
$RemoveM = GUICtrlCreateMenuitem ("Remove this library",$ToolM)
GUICtrlCreateMenuitem ("",$ToolM)
$ToolBoxM = GUICtrlCreateMenuitem ("ToolBox",$ToolM)

$HelpM = GUICtrlCreateMenu ("Help")
$TopicsM = GUICtrlCreateMenuitem ("Topics",$HelpM)
$AboutM = GUICtrlCreateMenuitem ("About",$HelpM)

$GUI_ActiveX = GUICtrlCreateObj($oForm,0,0,$dm0[3],$dm0[4]-39)
If $ShowTools <> 0 Then WinMove('Toolbox','',$dm1[1],$dm1[2])
$Status1C = GUICtrlCreateInput('',0,$dm0[4]-40,150,20,$ES_READONLY)
$Status2C = GUICtrlCreateInput('',150,$dm0[4]-40,$dm0[3]-150,20,$ES_READONLY)
GUISetState()
;WinSetOnTop($title & ' ' & $rev & ' ' & $auther, "", 1)
EndFunc

;==================================================================
;Form_MouseMove: X and Y location in statusline one - Event driven 
;no button, shift control, X, Y / no return
;==================================================================
Func Form_MouseMove($Button,$Shift,$X,$Y)
    GUICtrlSetData($Status1C,' DX: ' & Round($X,-1)  & '  DY: ' & Round($Y,-1))
EndFunc

;==================================================================
;ReadPrefs: read in the preferences from initbase
;argument: the initbase address, no returns
;==================================================================
Func ReadPrefs($Prefs)
$var = RegRead($Prefs, 'FormWindow')
If @error Then $var = '0 0 640 480';MainW: x y w h
$dm0 = StringSplit($var,' ')
$var = RegRead($Prefs, 'Toolbox')
If @error Then $var = '0 0';Toolbox: x y ( com object )
$dm1 = StringSplit($var,' ')
$ShowTools = RegRead($Prefs, 'ShowTools'); toolbox on  -2 / off 0
If @error Then $ShowTools = 0
EndFunc

;==================================================================
;WritePrefs: writes the preferences back into Init base
;argument: the initbase address, return 1 failure / 0 succes
;==================================================================
Func WritePrefs($Prefs)
    $tmp = WinGetPos($MainW)
    RegWrite($Prefs, 'FormWindow', 'REG_SZ', $tmp[0] & ' ' & $tmp[1] & ' ' & $tmp[2]-8 & ' ' & $tmp[3]-34)
    If @error Then Return 1
        If WinExists('Toolbox') then
            $tmp = WinGetPos('Toolbox')
            RegWrite($Prefs, 'Toolbox', 'REG_SZ', $tmp[0] & ' ' & $tmp[1])
        EndIf
        RegWrite($Prefs, 'ShowTools', 'REG_SZ',$oForm.ShowToolBox)
Return 0
EndFunc

;==================================================================
;ReadComLib: Read in what com obect matches
;argument - the library / return array variable
;==================================================================
Func ReadComLib($file)
$ID = FileOpen($File,0)
$a = 0
Dim $tmp[9999]
While 1
    $Line = FileReadLine($ID)
    If @error Then Exitloop
    $a = $a + 1
    $tmp[$a] = $line
WEnd
$tmp[0] = $a
FileClose($ID)
Return $tmp
EndFunc

; ==================================================================
; Exits - Exit all windows, write preferences and close library
; arguments no / returns no
; ==================================================================
Func Exits()
    $oMyError = 0
    $oFormEvt = 0
    $oForm = 0
Exit
EndFunc

Func MyErrFunc($r,$a)
EndFunc

;================================================================== -------------------------------------------------------- Macros
;Preview: Toggle preview mode on off - Macro support
;arguments no / return 1 on, 0 off
;==================================================================
Func Preview()
If $oForm.Designmode = True Then
    $oForm.Designmode = 0
    $a = 0
Else
    $oForm.Designmode = -1
    $a = 1
EndIf
Return $a
EndFunc

;==================================================================
;ToggleToolBox: Toggle TollBox on / Off - Macro support
;argument no / return no 
;==================================================================
Func ToggleToolBox()
$ShowTools = $oForm.ShowToolBox
If $ShowTools = True Then
    $ShowTools = False
Else
    $ShowTools = -2
EndIf
$oForm.ShowToolBox = $ShowTools
If WinExists('Toolbox') Then WinMove('Toolbox','',$dm1[1],$dm1[2])
EndFunc

;================================================================== works but buggy
;ClearToNew: Clear all objects from window - macro support
;arguments no / return no
;==================================================================
Func ClearToNew()
Dim $MyControls = $oForm.Count - 1
With $oForm
For $b = 1 To 10
    For $a = 0 To $MyControls
        .Remove($a) 
    Next
Next
EndWith
EndFunc

;==================================================================
;Savecript: Snap out all objects and match with library - Maro Support
;argument no / return no 
;==================================================================
Func SaveScript()
Dim $MyControls = $oForm.Count - 1
$c = ''
With $oForm
For $a = 0 TO $MyControls
;_say(ObjName(.Item($a),3))
    $c = $c & '$' & .Item($a).Name & ' = ObjCreate("' & ObjName(.Item($a),3) & '")' & @CR
    $c = $c & 'GUICtrlCreateObj($' & .Item($a).Name & ',' & .Item($a).Left & ',' & .Item($a).Top & ',' & .Item($a).Width & ',' & .Item($a).Height & ')' & @CR
    $c = $c & 'With ' & '$' & .Item($a).Name & '; ' & .Item($a).Name & ' object pool start...' & @CR
    

;_say(.Item($a))
    $aProperties = ObjectGetProperties(.Item(0))
    
    for $Property in $aProperties; Display each property in Editbox
   ;_say(.Item($a).Name & ' ' & $a)
       ;_say($Property & ' = ' & Execute( .Item($a) & '.' & $Property  ))
            _say($Property & ' = ' & Execute( "$oButton1." & $Property  ))
           ;_say(Execute( .Item($a) & '.' & $Property))
    Next
Next
EndWith
;_Say($c)
ClipPut($c)
EndFunc

; -----------------------------------------------------------------------------------------
;DESCRIPTION:   Retrieves the description of all writable properties of the given Object.
;REQUIRES:      tlbinf32.dll  (distributed with Visual Studio)
;PARAMETERS:    $oApp - Pointer to an active object
;DATE:          2006-01-29
;AUTHOR:        SvenP
;CREDITS:       To Dale Holm
; -----------------------------------------------------------------------------------------
Func ObjectGetProperties($oObj)
Dim $oTLA, $oTLI, $TLIMember, $aProperties[1]
Const $cINVOKE_FUNC=1         ; A method (=function)
Const $cINVOKE_PROPERTYGET=2  ; Read-only property
Const $cINVOKE_PROPERTYPUT=4  ; Read/write property
Const $cINVOKE_PROPERTYPUTREF=8  ; Reference property

if not IsObj($oObj) then Return

$oTLA = ObjCreate("TLI.TLIApplication"); oTLA is a _TLIApplication interface
If @error then _say("TLI.TLIApplication not available...")
$oTLI   = $oTLA.InterfaceInfoFromObject($oObj); oTLI is a InterfaceInfo interface

$oTypeInfo = $oTLA.ClassInfoFromObject($oObj)
_say($oTypeInfo.Parent.ContainingFile)
For $TLIMember in $oTLI.Members         ; This interface contains both methods and properties
  ;if $TLIMember.InvokeKind = $cINVOKE_PROPERTYPUT then; Get only WRITABLE properties
        Redim $aProperties[UBound($aProperties)+1]  ; We don't know the number of properties in advance
        $aProperties[UBound($aProperties)-1] = $TLIMember.Name; Add the name of the property to array.'
        _say($aProperties[UBound($aProperties)-1])
  ;EndIf
Next
return $aProperties
EndFunc

Func Write()
    $oCX = ObjCreate("WMPlayer.OCX.7")
    $GUIActiveX = GUICtrlCreateObj($oCX, 0, 0 , 640 , 555 )
    $oCXEvt = ObjEvent($oCX,"Event_")
EndFunc

Func Discription($a)
;$a = 'TDCCtl.TDCCtl.1';'FlashFactory.FlashFactory.1'
$var = RegRead('HKEY_CLASSES_ROOT\' & $a & '\CurVer','')
If $var = '' Then
    $var = RegRead('HKEY_CLASSES_ROOT\' & $a & '\CLSID','')
    $var = RegRead("HKEY_CLASSES_ROOT\CLSID\" & $var & '\ProgID','')
EndIf
$c = $c & $var
EndFunc

I never did finished the application ( a activex scripting generator ) - it's just a fast wrapup

kjactive :)

Edited by kjactive

Share this post


Link to post
Share on other sites

Hi kjactive, thanks a lot for taking the trouble of answering my question. But I don't seem to be capable to taking benefit from your example. I would have to solicit other friends who have a working example to answer my question.

Best regards,

CYCho

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hallo Cycho

I just remembered that the PROGID form.form.1 component was the old freeware fm20.dll from MS, still available on the net

read more at this link

http://support.microsoft.com/kb/224305

Put the component into system32 and initiate the component with 'regsvr32 fm20.dll' in a commandline

kjactive :)

Edited by kjactive

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0