Jump to content

Playing avi problem


Recommended Posts

I've been using wmp as my avi object video player. JUST noticed when I resize the window, the video does not resize. I've tried the GUI_DOCKAUTO, I've tried window resizing, nothing works. This doesn't make sense to me because the actual wmp program can resize, so why can't I do it from an object. Stretchtofit doesn't work outside IE according to msdn. I looked at the MCI stuff, but that doesn't seem to maintain the video aspect ratio. Does anyone know a solution.....prefer wmp....or a different video object to use.

Edited by Champak
Link to comment
Share on other sites

  • 2 weeks later...

The best way to control wmplayer is through IE:

; Re-sizing a re-worked wmplayer:
; GUICtrlSetPos isn't supposed to work with GUICtrlCreateObj but it does okay here ...
#include <IE.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
Opt("MustDeclareVars", 1)
Global $videoPath, $oIE, $o_Plyr, $s_PlayerObjId, $msg, $gui, $width, $height, $oCtrl, $pos, $w, $h
$s_PlayerObjId = "wmplayerID"

$width = 600
$height = 450

$videoPath = FileOpenDialog("Choose a video file", @MyDocumentsDir, "Videos (*.avi;*.mpeg;*.mpg;*.wmv)", 3)

$gui = GUICreate("", $width, $height, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MAXIMIZEBOX))
GUISetState()

$o_Plyr = playVideo($oIE, $s_PlayerObjId, $videoPath, 0, 0, $width, $height)
Sleep(300)

;$o_Plyr.controls.play()
;Sleep(3000)
;$o_Plyr.controls.pause()
;Sleep(3000)
;$o_Plyr.controls.stop()

$pos = WinGetClientSize($gui)
$w = $pos[0]
$h = $pos[1]
While $msg <> $GUI_EVENT_CLOSE
    Sleep(40)
    $msg = GUIGetMsg()
    $pos = WinGetClientSize($gui)
    If $pos[0] <> $w Or $pos[1] <> $h Then _ResizeWmplayerCtrl()
WEnd
$oIE = 0

Func _ResizeWmplayerCtrl()
    Local $retV
    $retV = GUICtrlSetPos($oCtrl, 0, 0, $pos[0], $pos[1])
    If Not $retV Then MsgBox(0, "", "Problem with GUICtrlSetPos")
    $w = $pos[0]
    $h = $pos[1]
    $o_Plyr.style.width =  $pos[0]
    $o_Plyr.style.height = $pos[1]
EndFunc

Func playVideo(ByRef $oIE, ByRef $s_PlayerObjId, $vid, $i_Left, $i_Top, $i_Width, $i_Height)

    Local $blank, $oDoc, $oBody, $oBodyStyle, $IEReadyState, $o_Plyr
    $oIE = _IECreateEmbedded()
    $oCtrl = GUICtrlCreateObj($oIE, $i_Left, $i_Top, $i_Width, $i_Height)
;   GUICtrlSetResizing($oCtrl, $GUI_DOCKAUTO)
    _IENavigate($oIE, "about:blank", 1)
    _IELoadWait($oIE, 180, 4000)
    Do
        Sleep(50)
        $oDoc = $oIE.document
    Until IsObj($oDoc)
    Sleep(25)

    $oBody = $oDoc.body
    $oBody.scroll = "no"
    $oBodyStyle = $oBody.style
;   $oBodyStyle.overflow = "hidden"
    $oBodyStyle.margin = "0px"
    $oBodyStyle.border = "0px"
    $oBodyStyle.padding = "0px"
    $oBodyStyle.background = "#000000"
    $o_Plyr = $oDoc.createElement("OBJECT")
    With $o_Plyr
        .id = $s_PlayerObjId
        .style.margin = "0px"
        .style.border = "0px"
        .style.padding = "0px"
        .style.width = $i_Width
        .style.height = $i_Height
        .classid = "CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
        .uiMode = "none"; invisible, none, mini, full
        .StretchToFit = "true"
        .settings.setMode("loop", "true")
        .URL = $vid
    EndWith
    $oBody.appendChild($o_Plyr)
    Return $o_Plyr
EndFunc

GUICtrlSetPos isn't supposed to work with GUICtrlCreateObj but it does okay here.

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

That code in my last post is probably more memory intensive than it needs to be because I think there might be some better way to call _ResizeWmplayerCtrl() function, like via ObjEvent or something.

Das Häschen benutzt Radar

Link to comment
Share on other sites

That's cool, thanks. Here is a reworked version that makes the resizing an event function. I don't think you can get the memory resources down any lower, I think that is just wmp. I was trying to do that myself because my previous setup uses pretty much the same amount.

; Re-sizing a re-worked wmplayer:
; GUICtrlSetPos isn't supposed to work with GUICtrlCreateObj but it does okay here ...
#include <IE.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global $videoPath, $oIE, $o_Plyr, $s_PlayerObjId, $msg, $gui, $width, $height, $oCtrl, $pos, $w, $h
$s_PlayerObjId = "wmplayerID"

$width = 600
$height = 450

$videoPath = FileOpenDialog("Choose a video file", @MyDocumentsDir, "Videos (*.avi;*.mpeg;*.mpg;*.wmv)", 3)

$gui = GUICreate("", $width, $height, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MAXIMIZEBOX))
GUISetOnEvent($GUI_EVENT_RESIZED, "_Resize")
GUISetBkColor(-1, 0x000000)
GUISetState()

$o_Plyr = playVideo($oIE, $s_PlayerObjId, $videoPath, 0, 0, $width, $height)
Sleep(300)

;$o_Plyr.controls.play()
;Sleep(3000)
;$o_Plyr.controls.pause()
;Sleep(3000)
;$o_Plyr.controls.stop()

$pos = WinGetClientSize($gui)
$w = $pos[0]
$h = $pos[1]
While $msg <> $GUI_EVENT_CLOSE
    Sleep(60)
WEnd
$oIE = 0

Func _Resize()

    $pos = WinGetClientSize($gui)
    If $pos[0] <> $w Or $pos[1] <> $h Then _ResizeWmplayerCtrl()    

EndFunc

Func _ResizeWmplayerCtrl()
    Local $retV
    $retV = GUICtrlSetPos($oCtrl, 0, 0, $pos[0], $pos[1])
    If Not $retV Then MsgBox(0, "", "Problem with GUICtrlSetPos")
    $w = $pos[0]
    $h = $pos[1]
    $o_Plyr.style.width =  $pos[0]
    $o_Plyr.style.height = $pos[1]
EndFunc

Func playVideo(ByRef $oIE, ByRef $s_PlayerObjId, $vid, $i_Left, $i_Top, $i_Width, $i_Height)

    Local $blank, $oDoc, $oBody, $oBodyStyle, $IEReadyState, $o_Plyr
    $oIE = _IECreateEmbedded()
    $oCtrl = GUICtrlCreateObj($oIE, $i_Left, $i_Top, $i_Width, $i_Height)
;   GUICtrlSetResizing($oCtrl, $GUI_DOCKAUTO)
    _IENavigate($oIE, "about:blank", 1)
    _IELoadWait($oIE, 180, 4000)
    Do
        Sleep(50)
        $oDoc = $oIE.document
    Until IsObj($oDoc)
    Sleep(25)

    $oBody = $oDoc.body
    $oBody.scroll = "no"
    $oBodyStyle = $oBody.style
;   $oBodyStyle.overflow = "hidden"
    $oBodyStyle.margin = "0px"
    $oBodyStyle.border = "0px"
    $oBodyStyle.padding = "0px"
    $oBodyStyle.background = "#000000"
    $o_Plyr = $oDoc.createElement("OBJECT")
    With $o_Plyr
        .id = $s_PlayerObjId
        .style.margin = "0px"
        .style.border = "0px"
        .style.padding = "0px"
        .style.width = $i_Width
        .style.height = $i_Height
        .classid = "CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
        .uiMode = "none"; invisible, none, mini, full
        .StretchToFit = "true"
        .settings.setMode("loop", "true")
        .URL = $vid
    EndWith
    $oBody.appendChild($o_Plyr)
    Return $o_Plyr
EndFunc

One thing that was concerning me, even with how I previously had it, the context-menu is raised with a right click....I will do a search, but I'm asking here first anyway since I'm responding....is there a way to change the context-menu to a left click ONLY within the video window and nowhere else on the computer or application? Or, preferably make sure full screen doesn't/can't set topmost(So I can use my own navigation buttons)?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...