Sign in to follow this  
Followers 0
qazwsx

Windows media player com help

5 posts in this topic

Here is my code:

$oMedia = ObjCreate("MediaPlayer.MediaPlayer.1")
If not @error then
    Msgbox(0,"Remote ObjCreate Test","ObjCreate() of a remote Mediaplayer Object successful !")
    $omedia.controls.pause()
Else
    Msgbox(0,"Remote ObjCreate Test","Failed to open remote Object. Error code: " & hex(@error,8))
Endif

Most of that is from the help file and i got the ".controls.pause()" from the msdn2 site. I ahve never used com before and i ahve no idea what im doing. Any help is appreciated.

Share this post


Link to post
Share on other sites



I believe you use $omedia.controls.pause() with the version 7 of media player but just $omedia.pause() with the 6.4 version.

This worked with my 6.4 player:

$oMedia = ObjCreate("MediaPlayer.MediaPlayer.1")

If not @error then

Msgbox(0,"Remote ObjCreate Test","ObjCreate() of a remote Mediaplayer Object successful !")

$oMedia.open("asong.mp3")

sleep(8000)

$omedia.pause()

Sleep(5000)

$oMedia.play()

sleep(5000);

MsgBox(0,"","It worked")

Else

Msgbox(0,"Remote ObjCreate Test","Failed to open remote Object. Error code: " & hex(@error,8))

Endif

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hallo Sccrtven93

I made a small example script that illustrates some of the basics with the activex components related to the OLD MediaPlayer, Back in memory I remembered that the MediaPlayer.MediaPlayer.1 ID should be a pointer to the latest WMPlayer on the local system, but it do not point to rev. 10 in my case so I had to strip some of the latest commands off - but it should show some points on the basics I hope, tricking events included...

There are a lot of ways to inpliments activex components but two basic ways are

1. To catch return values and interact with commands ( Look into 'While 1' handle function )

2. Let the component fire some buildin events and let these do the trick ( Keyboard example )

This script is an example script but show both ways, that's why it's a little messy

; Author:   Kåre Johansson
; Description: Very Simple example: Embedding MediaPlayer.MediaPlayer.1" => "wmplayer.ocx" OLD
; Date: 1.9.07
; The application automatically grows/shrinks to fit the specified object width and height, although
; the video itself will not automatically grow beyond 100%.

#include <GUIConstants.au3>

$oRP = ObjCreate("MediaPlayer.MediaPlayer.1")
If Not IsObj($oRP) Then 
    MsgBox(48,"ERROR...","object failed")
    Exit
EndIf

GUICreate ("Embedded Preview control Test", 620, 425, -1, -1,BitOr($WS_OVERLAPPEDWINDOW,$WS_VISIBLE,$WS_CLIPSIBLINGS))
$TagsPageC = GuiCtrlCreateLabel('Visit Tags Page', 5, 405, 100, 15, $SS_CENTER)

$GUIActiveX = GUICtrlCreateObj( $oRP, 10, 10 , 600 , 285 )
$oRPEvt = ObjEvent($oRP,"MediaPlayer_")

With $oRP; Object tag pool
    .Rate = 10
    .AutoStart = True
    .playcount = 3; 0,1,2,3
    .displaysize = True
    .windowlessVideo = True
    .showControls = True
    .EnableContextMenu = True
    .ShowPositionControls = True
    .ShowStatusBar = True
    .ShowTracker = True
    .EnableTracker = True
    .showaudiocontrols = True
    .EnablePositionControls = True
    .Enabled = True
    .ShowDisplay = True
    .ShowGotoBar = True
    .Mute = True
    .Filename = "Test.wmv"; "Test.avi" , Test.wav ec.; full path or placed in local path
    .Play; stop pause
Consolewrite(.openState & @CRLF); 0 Not ready, 6 Playing
Consolewrite(.currentPosition )
Consolewrite(.duration & @CRLF)
Consolewrite(.PlayState & @CRLF); 0 Stopped, 1 Pause, 2 playing
   .SendKeyboardEvents = true
;~  .ClickToPlay = True
;~ .AutoRewind = True
    .CurrentPosition = 100
    .volume = 0; -10000
    .balance = -10000; -10000
.AboutBox
EndWith

GUISetState();Show GUI

While 1
    $msg = GUIGetMsg()
    If $oRP.currentPosition = 10 Then $oRP.Pause; take return values and do an interact example

    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $TagsPageC
            Run(@ComSpec & ' /c start http://www.w3schools.com/media/media_playerref.asp','', @SW_HIDE)
    EndSelect
WEnd

GUIDelete ()
$oRP.Stop; stop running movie or the computer could be struckt
$oRP = 0; Free the compoment
Exit

; The keyboard event handle function - example
Func MediaPlayer_KeyDown($a)
    ConsoleWrite('Keyboard event:' & $a & @CRLF)
EndFunc

The latest player Progid is WMPlayer.OCX.7 ( in XP rev. 10 ) from the wmp.dll library, Clsid {6BF52A52-394A-11d3-B153-00C04F79FAA6} - Hope this can help you diealing with components

Commands available to Medieplayer 2 component

http://www.myplugins.info/guids/typeinfo/t...B-0080C74C7E95}

Command available to the Medieplayer 4 component

http://www.myplugins.info/guids/typeinfo/t...3-00C04F79FAA6}

kjactive :)

Edited by kjactive

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hallo Sccrstvn93

dont quite understand your code. Also is there an easier way other than com object to use hotkeys for play pause and skip

Try Controls like - The exits function is that kind of function, It stops the play

While 1
  $msg = GUIGetMsg()
  Select
     Case msg = $Stop_Control
        $oRP.Stop
     Case msg = $Play_Control
        $oRP.Play

.Play^ ERROR

That's because there is no loaded file - you has to check ready state before moveing around in the movie....

Simple as that - my script was only an example script, If you got medieplayer 11, why not use this, it's progid WMPlayer.OCX.7, But one thing to know about this component is that it is self configurated / resized ec. and the older components has serious bugs too

kjactive :)

Edited by kjactive

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I've messed around with the latest Medieplayer rev. 11 to lookup new things, not much but here it is...

; Author:   Kåre Johansson
; Description: Very Simple example: Embedding "WMPlayer.OCX.7" => "wmp.dll" Latest rev, 11
; Date: 2.9.07
; The application automatically grows/shrinks to fit the specified object width and height, although
; the video itself will not automatically grow beyond 100%.

#include <GUIConstants.au3>
#include <words.au3>

Global $oRP = ObjCreate("WMPlayer.OCX.7")
If Not IsObj($oRP) Then; check component
    MsgBox(48,"ERROR...","object failed")
    Exit
EndIf
#cs
Global $colCDROMs = $oRP.cdromCollection; DVD collection function
if $colCDROMs.Count >= 1 then
        For $i = 0 to $colCDROMs.Count - 1
                $colCDROMs.Item($i).Eject
        Next
EndIf
#ce
GUICreate ("Embedded Medieplayer control Test", 620, 425, -1, -1,BitOr($WS_OVERLAPPEDWINDOW,$WS_VISIBLE,$WS_CLIPSIBLINGS))
$TagsPageC = GuiCtrlCreateLabel('Visit Commands Page', 5, 405, 150, 15, $SS_CENTER)
GuiCtrlSetFont(-1,9,400,4)
GuiCtrlSetColor(-1,0x0000ff)
GuiCtrlSetCursor(-1,0)

Global $GUIActiveX  = GUICtrlCreateObj( $oRP, 10, 10 , 600 , 385 )
Global $oRPEvt = ObjEvent($oRP,"MediaPlayer_")

With $oRP; Object tag pool
    .fullScreen = True
    .windowlessVideo = True
    .stretchToFit = True
    .URL = "Test.wmv"; example: 'g:\Video\Madrid.wmv'
    .enableContextMenu = True
    .enabled = True
    .Controls.currentPosition = 180; move to location in movie
;~  .Controls.Play / pause and Stop
    .uiMode = "Full"; none / mini full
    .settings.autostart = True
    .settings.mute = False
    .settings.volume = 50; 0 - 100
    .settings.Balance = 0; -100 to 100
EndWith

GUISetState();Show GUI
While 1
    $msg = GUIGetMsg()
    Consolewrite($oRP.controls.currentPosition & @CRLF); display current position in movie
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $TagsPageC
            Run(@ComSpec & ' /c start http://www.myplugins.info/guids/typeinfo/typeinfo.php?clsid={6BF52A52-394A-11d3-B153-00C04F79FAA6}','', @SW_HIDE)
    EndSelect
WEnd

GUIDelete ()
$oRP = 0; Free the compoment
Exit

; Event function tricks when double click the mouse
Func MediaPlayer_DoubleClick($Button, $ShiftState, $fX, $fY)
    If $oRP.playState = 3 Then
        $oRP.Controls.Pause; pause
    Else
        With $oRP
            .Controls.Play; Play
            If .settings.IsAvailable('Rate') Then .settings.rate = 2; check settings and speedup movie if this is an option
        EndWith
    Endif
EndFunc

This is a little different from the previous example as there is an event that directly point to the component - Doubleclick mouse will pause / play movie ( remember to change movie tag ) - there is a link to a command page in the window, NOTE - some components is split into two or more components ( player and control panel ec. ) but this is all in one model and looks like it's ment to be used with HTML or semilare web target languages like Java...

Still a messy example script but should get you on the hot spots...

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