Jump to content

[SOLVED]Embedded WMPlayer window behaves curiously when another window is minimized


Recommended Posts

Hi there! I wish every one of you to be healthy and happy.

I made the following code borrowing mainly from @dragan's post.
 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

Global $mainGUI = GUICreate("Load and play a video file", 400, 200, -1, -1)
Global $inputFile = GUICtrlCreateInput("", 20, 50, 280, 20)
Global $btnLoad = GUICtrlCreateButton("Load", 300, 48, 80, 23)
Global $btnPlay = GUICtrlCreateButton("Play", 160, 100, 80, 23)
GUISetState()

Global $videoHeight = @DesktopHeight/2, $videoWidth = $videoHeight, $videoLeft = @DesktopWidth-$videoWidth, $IEControl
Global $videoGUI = GUICreate("Video Control", $videoWidth, $videoHeight, $videoLeft, 0, $WS_OVERLAPPEDWINDOW)
Global $oIE = _GUICtrl_CreateWMPlayer()
GUISetState (@SW_HIDE, $videoGUI)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
Global $oPlayer = _IEGetObjById($oIE, "objWMPlayer")

Global $aMsg
While 1
    $aMsg = GUIGetMsg(1)
    If $aMsg[1] = $mainGUI Then
        If $aMsg[0] = $GUI_EVENT_CLOSE Then
            Exit
        ElseIf $aMsg[0] = $btnLoad Then
            Local $sFile = FileOpenDialog("Open Videos", @UserProfileDir, "Movies (*.3gp;*.mp4;*.avi;*.wmv;*.flv)")
            GUICtrlSetData($inputFile, $sFile)
            If @error Then Exit
        ElseIf $aMsg[0] = $btnPlay Then
            GUISetState(@SW_SHOW, $videoGUI)
            $oPlayer.URL = $sFile
            $oPlayer.Controls.Play
            While $oPlayer.playState <> 3
                Sleep(10)
            WEnd
            Local $sWidth = $oPlayer.currentMedia.imageSourceWidth, $sHeight = $oPlayer.currentMedia.imageSourceHeight
            If $sWidth > 0 Then
                Local $iWidth = $videoHeight*$sWidth/$sHeight
                WinMove($videoGUI, "", @DesktopWidth-$iWidth, 0, $iWidth+16, $videoHeight+39)
            EndIf
        EndIf
    ElseIf $aMsg[1] = $videoGUI And $aMsg[0] = $GUI_EVENT_CLOSE Then
        $oPlayer.Controls.Stop
        GUISetState (@SW_HIDE, $videoGUI)
        ContinueLoop
    ElseIf $oPlayer.playState = 1 Or $oPlayer.playState = 8 Then
        GUISetState (@SW_HIDE, $videoGUI)
        ContinueLoop
    EndIf
WEnd

Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
    Local $xClient, $yClient
    $xClient = BitAND($ilParam, 0x0000FFFF)
    $yClient = BitShift($ilParam, 16)
    GUICtrlSetPos($IEControl, 0, 0, $xClient, $yClient)
    if NOT @error Then
        if IsObj($oPlayer) Then $oPlayer.width = $xClient;
        if IsObj($oPlayer) Then $oPlayer.height = $yClient;
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Func _GUICtrl_CreateWMPlayer()
    Local $myIE_Obj = _IECreateEmbedded ()
    $IEControl = GUICtrlCreateObj($myIE_Obj, 0, 0, $videoWidth, $videoHeight)
    _IENavigate($myIE_Obj, "about:blank")
    Local $htmlWMP
    $htmlWMP = '' _
        & @CR & '<body style="margin:0;padding:0" >' _
        & @CR & '<OBJECT' _
        & @CR & 'ID="objWMPlayer"' _
        & @CR & 'STYLE="margin:0;padding:0"' _
        & @CR & 'HSPACE="0"' _
        & @CR & 'VSPACE="0"' _
        & @CR & 'BORDER="0"' _
        & @CR & 'WIDTH="' & $videoWidth & '"' _
        & @CR & 'HEIGHT="' & $videoHeight & '"' _
        & @CR & 'CLASSID="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"' _
        & @CR & 'STANDBY="Loading Windows Media Player components..."' _
        & @CR & 'TYPE="application/x-ms-wmp">' _
        & @CR & '<PARAM NAME="enableContextMenu" VALUE="true">' _
        & @CR & '<PARAM NAME="enableFullScreenControls" VALUE="true">' _
        & @CR & '<PARAM NAME="enabled" VALUE="true">' _
        & @CR & '<PARAM NAME="playCount" VALUE="1">' _
        & @CR & '<PARAM NAME="stretchToFit" VALUE="true">' _
        & @CR & '<PARAM NAME="uiMode" VALUE="none">' _
        & @CR & '<PARAM NAME="videoBorderWidth" VALUE="5">' _
        & @CR & '<PARAM NAME="volume" VALUE="100">' _
        & @CR & '<PARAM NAME="windowlessVideo" VALUE="false">' _
        & @CR & '</OBJECT>' _
        & @CR & '</body>'
    _IEDocWriteHTML ($myIE_Obj, $htmlWMP)
    _IEAction ($myIE_Obj, "refresh")
    $myIE_Obj.document.body.scroll = "no"
    $myIE_Obj.document.body.style.borderColor = "#000000"
    Return $myIE_Obj
EndFunc ;==>_GUICtrl_CreateWMPlayer

This works usually OK, but the embedded WMP behaves abnormally when the 2 windows are minimized and restored depending on which one is minimized and restored first.

While video is playing:
1. Minimize $mainGUI, then the $videoGUI becomes blank.
2. Minimize both and restore $videoGUI first and then the $mainGUI, then the video size in the $videoGUI is changed to it's original source image size.
Please help me to understand what is the cause of this behaviour and how I can prevent it. Thnaks in advance.

Edited by CYCho
Link to post
Share on other sites

I found the cause and the problem was solved. The culprit was WM_SIZE function which is triggered not only by $videoGUI but also by any window. So I added

If $hWnd <> $videoGUI Then Return 0

in the beginning of the function and the problem is gone. Thanks for your attention.

Edited by CYCho
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By JuniorCoder
      I'm having a issue loading new media to the embedded wmp. on line 127
      GUI code.zip
    • By dost0011
      Hi,
      I've a problem: i want to use "WMPlayer.ocx" to change the balance to play the sounds from the left channel or the right channel. But it doesn't work - the result is always from both channels and I don't know what to change. Could you help please?
      msdn.microsoft.com/en-us/libra…61(v=winembedded.70).aspx
      here from -10000 to 10000.
      msdn.microsoft.com/en-us/libra…op/dd564326(v=vs.85).aspx
      here from -100 to 100
      But both doesn't work
       
      Balance.au3
×
×
  • Create New...