Announcement

Collapse
No announcement yet.

Playing video file in a control using MCI

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Playing video file in a control using MCI

    Hi guys,

    I have a rather straightforward question: what am I doing wrong ;-)?

    The following code does nothing more than attempt to play a video file whose path you enter into the box on the top in a label control.

    With DivX/XviD files (regardless of source), it plays the video at several times the normal speed, minus sound.

    For MPG files, only the sound is played with no video.

    Any ideas where I am going wrong?

    Thanks,

    Oliver

    Code:
    #PBFORMS CREATED V1.50
    '------------------------------------------------------------------------------
    ' The first line in this file is a PB/Forms metastatement.
    ' It should ALWAYS be the first line of the file. Other
    ' PB/Forms metastatements are placed at the beginning and
    ' end of "Named Blocks" of code that should be edited
    ' with PBForms only. Do not manually edit or delete these
    ' metastatements or PB/Forms will not be able to reread
    ' the file correctly.  See the PB/Forms documentation for
    ' more information.
    ' Named blocks begin like this:    #PBFORMS BEGIN ...
    ' Named blocks end like this:      #PBFORMS END ...
    ' Other PB/Forms metastatements such as:
    '     #PBFORMS DECLARATIONS
    ' are used by PB/Forms to insert additional code.
    ' Feel free to make changes anywhere else in the file.
    '------------------------------------------------------------------------------
    
    #COMPILE EXE
    #DIM ALL
    
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    #IF NOT %DEF(%WINAPI)
        #INCLUDE "WIN32API.INC"
    #ENDIF
    #PBFORMS END INCLUDES
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_MAINFRAME =  101
    %IDC_PATH      = 1001
    %IDC_VIDEO     = 1002
    %IDC_PLAY      = 1003
    %IDC_STOP      = 1004
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowMAINFRAMEProc()
    DECLARE FUNCTION ShowMAINFRAME(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        ShowMAINFRAME %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowMAINFRAMEProc()
        LOCAL x$,vhndl&,serr&
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' Initialization handler
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
    
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CBCTL
                    CASE %IDC_STOP
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            CONTROL GET TEXT CBHNDL,%IDC_PATH TO x$
                            CALL mciSendString("close " + $DQ+x$+$DQ, "", %NULL, %NULL)
                        END IF
                    CASE %IDC_PLAY
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            CONTROL GET TEXT CBHNDL,%IDC_PATH TO x$
                            CONTROL HANDLE CBHNDL,%IDC_VIDEO TO vhndl&
                            serr&=mciSendString("open " + $DQ+x$+$DQ, "", %NULL, %NULL)
                            IF serr THEN
                                MSGBOX "Error opening."
                                EXIT FUNCTION
                            END IF
                            serr&=mciSendString("window " + $DQ + x$ + $DQ + " handle " + FORMAT$(vhndl&), BYVAL %NULL, 0, 0)
                            IF serr THEN
                                MSGBOX "Error setting window."
                                EXIT FUNCTION
                            END IF
                            serr&=mciSendString("play " + $DQ+x$+$DQ, "", %NULL, %NULL)
                            IF serr THEN
                                MSGBOX "Error playing."
                                EXIT FUNCTION
                            END IF
    
                        END IF
    
                END SELECT
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowMAINFRAME(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt AS LONG
    
    #PBFORMS BEGIN DIALOG %IDD_MAINFRAME->->
        LOCAL hDlg  AS DWORD
    
        DIALOG NEW  hParent, "Video Player", 70, 70, 408, 324, %WS_POPUP OR _
            %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _
            %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
            %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_WINDOWEDGE OR _
            %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
            %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD TEXTBOX, hDlg, %IDC_PATH, "", 0, 15, 315, 12
        CONTROL ADD LABEL,   hDlg, %IDC_VIDEO, "", 20, 35, 355, 260
        CONTROL ADD BUTTON,  hDlg, %IDC_PLAY, "&Play", 319, 15, 41, 15
        CONTROL ADD BUTTON,  hDlg, %IDC_STOP, "&Stop", 366, 15, 41, 15
    #PBFORMS END DIALOG
    
        DIALOG SHOW MODAL hDlg, CALL ShowMAINFRAMEProc TO lRslt
    
    #PBFORMS BEGIN CLEANUP %IDD_MAINFRAME
    #PBFORMS END CLEANUP
    
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
    ------------------

  • #2
    Hi Oliver,
    you need '%WS_CLIPSIBLINGS Or %WS_CLIPCHILDREN' for the style of the control '%IDC_VIDEO'

    Here is a small sample:

    Part_01_My_MCI.inc (save as My_MCI.inc):
    Code:
    '------------------------------------------------------------------------------------------------------------------------
    '%MM_MIDI_MAPPER     = 1   ' MIDI Mapper
    '%MM_WAVE_MAPPER     = 2   ' Wave Mapper
    '%MM_SNDBLST_MIDIOUT = 3   ' Sound Blaster MIDI output port
    '%MM_SNDBLST_MIDIIN  = 4   ' Sound Blaster MIDI input port
    '%MM_SNDBLST_SYNTH   = 5   ' Sound Blaster internal synthesizer
    '%MM_SNDBLST_WAVEOUT = 6   ' Sound Blaster waveform output
    '%MM_SNDBLST_WAVEIN  = 7   ' Sound Blaster waveform input
    '%MM_ADLIB           = 9   ' Ad Lib-compatible synthesizer
    '%MM_MPU401_MIDIOUT  = 10  ' MPU401-compatible MIDI output port
    '%MM_MPU401_MIDIIN   = 11  ' MPU401-compatible MIDI input port
    '%MM_PC_JOYSTICK     = 12  ' Joystick adapter
    '
    '
    '' flags for the dwItem field of MCI_STATUS_PARMS parameter block
    '%MCI_SEQ_STATUS_TEMPO   = &H00004002
    '%MCI_SEQ_STATUS_PORT    = &H00004003
    '%MCI_SEQ_STATUS_SLAVE   = &H00004007
    '%MCI_SEQ_STATUS_MASTER  = &H00004008
    '%MCI_SEQ_STATUS_OFFSET  = &H00004009
    '%MCI_SEQ_STATUS_DIVTYPE = &H0000400A
    '
    '
    '' flags for dwFlags parameter of MCI_STATUS command message
    '%MCI_STATUS_ITEM   = &H00000100
    '%MCI_STATUS_START  = &H00000200
    '
    '' flags for dwItem field of the MCI_STATUS_PARMS parameter block
    '%MCI_STATUS_LENGTH           = &H00000001
    '%MCI_STATUS_POSITION         = &H00000002
    '%MCI_STATUS_NUMBER_OF_TRACKS = &H00000003
    '%MCI_STATUS_MODE             = &H00000004
    '%MCI_STATUS_MEDIA_PRESENT    = &H00000005
    '%MCI_STATUS_TIME_FORMAT      = &H00000006
    '%MCI_STATUS_READY            = &H00000007
    '%MCI_STATUS_CURRENT_TRACK    = &H00000008
    '
    '------------------------------------------------------------------------------------------------------------------------
    
    #Include "mciavi.inc"
    #Include "digitalv.inc"
    
    Global wMciDeviceID	As Word
    '------------------------------------------------------------------------------------------------------------------------
    '
    '------------------------------------------------------------------------------------------------------------------------
    Function MCI_OPEN(ByVal hWndForm As Dword, ByVal sFileName As String, ByVal sDeviceType As String) As Long
    	Local dwReturn 		As Dword
    	Local dwFlags		As Dword
    	Local mciOpenParms	As MCI_OPEN_PARMS
    '-------------------------------------------
    
    	' Opens a waveform-audio device by specifying the device and file name.
    	mciOpenParms.lpstrElementName = StrPtr(sFileName)
    	mciOpenParms.lpstrDeviceType = StrPtr(sDeviceType)
    	dwFlags = %MCI_OPEN_TYPE Or %MCI_OPEN_ELEMENT
    
    	dwReturn = MciSendCommand(hWndForm, %MCI_OPEN, dwFlags, VarPtr(mciOpenParms))
    
    	If IsTrue(dwReturn) Then
    	 	Call Get_MCI_ERROR(hWndForm, Lo(Word,dwReturn), "MCI_OPEN")
        	Function = -1
    	Else
    		' The device opened successfully; get the device ID.
    		wMciDeviceID = mciOpenParms.wDeviceId
    		Function 	 = 0
      	End If
    End Function
    
    
    '------------------------------------------------------------------------------------------------------------------------
    '
    '------------------------------------------------------------------------------------------------------------------------
    Function MCI_CLOSE(ByVal hWndForm As Dword) As Long
    	Local dwReturn 	As Dword
    	Local dwFlags	As Dword
    '-------------------------------------------
    
    	' Closes all MCI devices opened by this application.
    	dwFlags = %MCI_WAIT
    	dwReturn = MciSendCommand(%MCI_ALL_DEVICE_ID, %MCI_Close, dwFlags, %Null)
    
    	If IsTrue(dwReturn) Then
    	 	Call Get_MCI_ERROR(hWndForm, Lo(Word,dwReturn), "MCI_Close")
        	Function = -1
    	Else
    	  	Function = 0
    	End If
    
    End Function
    
    '------------------------------------------------------------------------------------------------------------------------
    '
    '------------------------------------------------------------------------------------------------------------------------
    Function MCI_PlayMovie(ByVal hWndForm As Dword, ByVal wDevID As Word) As Long
    	Local dwReturn	As Dword
        Local dwFlags	As Dword
    	Local mciPlay 	As MCI_DGV_PLAY_PARMS
    '---------------------------------------
    
    	mciPlay.dwFrom 		= %MCI_FROM
    	mciPlay.dwTo 		= %MCI_TO
    	mciPlay.dwCallback 	= hWndForm
    	dwFlags = %MCI_NOTIFY 'Or %MCI_DGV_PLAY_REPEAT
    
    	' Send the MCI_PLAY command and return the result.
    	dwReturn = MciSendCommand(wDevID, %MCI_PLAY, dwFlags, VarPtr(mciPlay))
    
    	If IsTrue(dwReturn) Then
    	 	Call Get_MCI_ERROR(hWndForm, Lo(Word,dwReturn), "MCI_PlayMovie")
        	Function = -1
    	Else
    		Function = 0
    	End If
    
    End Function
    
    
    '------------------------------------------------------------------------------------------------------------------------
    '
    '------------------------------------------------------------------------------------------------------------------------
    Function MCI_Stop(ByVal hWndForm As Dword, ByVal wDevID As Word) As Long
    	Local dwReturn	As Dword
        Local dwFlags	As Dword
    	Local mciStop 	As MCI_GENERIC_PARMS
    '---------------------------------------
    
    	' Send the MCI_STOP command and return the result.
    	dwFlags = %MCI_NOTIFY
    	dwReturn = MciSendCommand(wDevID, %MCI_STOP, dwFlags, VarPtr(mciStop))
    
    	If IsTrue(dwReturn) Then
    	 	Call Get_MCI_ERROR(hWndForm, Lo(Word,dwReturn), "MCI_Stop")
        	Function = -1
    	Else
    		Function = 0
    	End If
    
    End Function
    
    
    '------------------------------------------------------------------------------------------------------------------------
    '
    '------------------------------------------------------------------------------------------------------------------------
    Function MCI_PlayWAVE(ByVal hWndForm As Dword, ByVal wDevID As Word) As Long
    	Local dwReturn	As Dword
        Local dwFlags	As Dword
    	Local mciPlay 	As MCI_PLAY_PARMS
    '---------------------------------------
    
    	mciPlay.dwCallback = hWndForm
    	dwFlags = %MCI_NOTIFY 'Or %MCI_DGV_PLAY_REPEAT
    
    	' Send the MCI_PLAY command and return the result.
    	dwReturn = MciSendCommand(wDevID, %MCI_PLAY, dwFlags, VarPtr(mciPlay))
    
    	If IsTrue(dwReturn) Then
    	 	Call Get_MCI_ERROR(hWndForm, Lo(Word,dwReturn), "MCI_PlayMovie")
        	Function = -1
    	Else
    		Function = 0
    	End If
    
    End Function
    
    
    '------------------------------------------------------------------------------------------------------------------------
    '
    '------------------------------------------------------------------------------------------------------------------------
    Function MCI_Put(ByVal hWndForm As Dword, ByVal hDevice As Dword, ByVal wDevID As Word, ByVal rectDest As Rect) As Long
    	Local dwReturn	As Dword
        Local dwFlags	As Dword
    	Local mciPut 	As MCI_DGV_PUT_PARMS
    	Local mciWindow As MCI_DGV_WINDOW_PARMS
    '---------------------------------------
    
    	mciWindow.hWnd = hDevice
    	dwReturn = MciSendCommand(wDevID, %MCI_WINDOW, %MCI_DGV_WINDOW_HWND, VarPtr(mciWindow))
    
        'prüfen ob ein Fehler aufgetreten
    	If IsTrue(dwReturn) Then
    	 	Call Get_MCI_ERROR(hWndForm, Lo(Word,dwReturn), "MCI_Put")
        	Function = -1
    	Else
    		Function = 0
    	End If
    
     	mciPut.rc = rectDest
        dwReturn = MciSendCommand(wDevID, %MCI_PUT, %MCI_DGV_PUT_DESTINATION, VarPtr(mciPut))
    
        'prüfen ob ein Fehler aufgetreten
    	If IsTrue(dwReturn) Then
    	 	Call Get_MCI_ERROR(hWndForm, Lo(Word,dwReturn), "MCI_Put")
        	Function = -1
    	Else
    		Function = 0
    	End If
    
    End Function
    
    
    '------------------------------------------------------------------------------------------------------------------------
    ' Begin recording and record for the specified number of
    ' milliseconds. Wait for recording to complete before continuing.
    ' Assume the default time format for the waveform-audio device (milliseconds).
    '------------------------------------------------------------------------------------------------------------------------
    Function MCI_Record(ByVal hWndForm As Dword, ByVal wDevID As Word, ByVal lmSek As Word) As Long
    	Local dwReturn	As Dword
        Local dwFlags	As Dword
    	Local mciRecord As MCI_RECORD_PARMS
    '---------------------------------------
    
    	mciRecord.dwCallback = hWndForm
    	mciRecord.dwFrom 	 = 0
    	mciRecord.dwTo 		 = lmSek
    	dwFlags = %MCI_TO Or %MCI_WAIT
    
    	' Send the MCI_PLAY command and return the result.
    	dwReturn = MciSendCommand(wDevID, %MCI_RECORD, dwFlags, VarPtr(mciRecord))
    
    	If IsTrue(dwReturn) Then
    	 	Call Get_MCI_ERROR(hWndForm, Lo(Word,dwReturn), "MCI_PlayMovie")
        	Function = -1
    	Else
    		Function = 0
    	End If
    
    End Function
    
    '------------------------------------------------------------------------------------------------------------------------
    ' Save the recording to a file named *.WAV.
    ' Wait for the operation to complete before continuing.
    '------------------------------------------------------------------------------------------------------------------------
    Function MCI_SAVE(ByVal hWndForm As Dword, ByVal wDevID As Word, ByVal sFileName As Asciiz * 255) As Long
    	Local dwReturn	As Dword
        Local dwFlags	As Dword
    	Local mciSave  	As MCI_SAVE_PARMS
    '---------------------------------------
    
        mciSave.dwCallback = hWndForm
     	mciSave.lpfilename = VarPtr(sFileName)
    	dwFlags = %MCI_WAIT
    
    	' Send the MCI_PLAY command and return the result.
    	dwReturn = MciSendCommand(wDevID, %MCI_SAVE, dwFlags, VarPtr(mciSave))
    
    	If IsTrue(dwReturn) Then
    	 	Call Get_MCI_ERROR(hWndForm, Lo(Word,dwReturn), "MCI_PlayMovie")
        	Function = -1
    	Else
    		Function = 0
    	End If
    
    End Function
    
    '------------------------------------------------------------------------------------------------------------------------
    '
    '------------------------------------------------------------------------------------------------------------------------
    Function MCI_Status(ByVal wDevID As Word, ByVal lStatus As Long) As Word
    	Local dwReturn	As Dword
        Local dwFlags	As Dword
    	Local mciStatus As MCI_STATUS_PARMS
    '---------------------------------------
    
    	mciStatus.dwItem = %MCI_STATUS_MODE
    	dwReturn = MciSendCommand(wDevID, %MCI_STATUS, %MCI_STATUS_ITEM, VarPtr(mciStatus))
    
        'prüfen ob ein Fehler aufgetreten
    	If IsTrue(dwReturn) Then
        	Function = -1      'Fehler, Kein Status verfügbar
    	Else
    		Function =  Lo(Word, mciStatus.dwReturn)   'Kein Fehler , Status retour
    	End If
    
    End Function
    
    
    '------------------------------------------------------------------------------------------------------------------------
    ' Use mciGetErrorString to get a textual description of an MCI error.
    ' Display the error description using MessageBox.
    '------------------------------------------------------------------------------------------------------------------------
    Function Get_MCI_ERROR(ByVal hWndForm As Dword, ByVal wError As Word, Optional ByVal sFrom As String) As Long
       	Local sErrorFrom	As String
    	Local szErrorBuf 	As Asciiz * 2024
    '-------------------------------------------------
    
        'prüfen ob sFrom übergeben wurde
     	If IsTrue(Len(sFrom)) Then
     		sErrorFrom = sFrom
     	Else
     		sErrorFrom = "MCI Error"
     	End If
    
    	'Error abrufen und anzeigen
    	If(mciGetErrorString(wError, szErrorBuf, SizeOf(szErrorBuf))) Then
    		MessageBox(hWndForm, ByCopy szErrorBuf & $CrLf, ByCopy sErrorFrom, %MB_OK Or %MB_DEFBUTTON1 Or %MB_ICONERROR Or %MB_APPLMODAL)
    	Else
    		MessageBox(hWndForm, ByCopy "Unbekannter Fehler der MCI-Function aufgetreten" & $CrLf, ByCopy "sErrorFrom", %MB_OK Or %MB_ICONERROR Or %MB_APPLMODAL)
      	End If
    
    End Function
    '-----------------------------------------------------
    Part_02_MCI.bas (save as MCI.bas):
    Code:
    #PBForms Created V1.51
    '------------------------------------------------------------------------------
    ' The first line in this file is a PB/Forms metastatement.
    ' It should ALWAYS be the first line of the file. Other
    ' PB/Forms metastatements are placed at the beginning and
    ' end of "Named Blocks" of code that should be edited
    ' with PBForms only. Do not manually edit or delete these
    ' metastatements or PB/Forms will not be able to reread
    ' the file correctly.  See the PB/Forms documentation for
    ' more information.
    ' Named blocks begin like this:    #PBFORMS BEGIN ...
    ' Named blocks end like this:      #PBFORMS END ...
    ' Other PB/Forms metastatements such as:
    '     #PBFORMS DECLARATIONS
    ' are used by PB/Forms to insert additional code.
    ' Feel free to make changes anywhere else in the file.
    '------------------------------------------------------------------------------
    #Compile Exe
    #Dim All
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #Include "My_MCI.inc"
    
    #PBForms Begin Includes
    #If Not %Def(%WINAPI)
        #Include "WIN32API.INC"
    #EndIf
    #PBForms End Includes
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBForms Begin Constants
    %IDD_MAINFRAME =  101
    %IDC_PATH      = 1001
    %IDC_VIDEO     = 1002
    %IDC_PLAY      = 1003
    %IDC_STOP      = 1004
    #PBForms End Constants
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    Declare CallBack Function ShowMAINFRAMEProc()
    Declare Function ShowMAINFRAME(ByVal hParent As Dword) As Long
    #PBForms Declarations
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    Function PBMain()
        ShowMAINFRAME %HWND_DESKTOP
    End Function
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CallBack Function ShowMAINFRAMEProc()
        Local rectLbl   As Rect
        Local sPath     As String
        Local hVideo    As Dword
    
    '------------------------
    
    
        Select Case As Long CbMsg
            Case %WM_INITDIALOG  ' Initialization handler
                Control Set Text CbHndl, %IDC_VIDEO, "Start movie"
    
    
            Case %WM_NCACTIVATE
                Static hWndSaveFocus As Dword
                If IsFalse CbWParam Then  ' Save control focus
                    hWndSaveFocus = GetFocus()
                ElseIf hWndSaveFocus Then    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                End If
    
            Case %WM_SYSCOMMAND     'Systemfunktion wurde gewählt
                Select Case LoWrd(CbWParam)
                    Case %SC_CLOSE
    
                        If MCI_Status(wMciDeviceID, %MCI_STATUS_MODE) <> Lo(Word,&hFFFF) Then
                            If (MCI_Stop(CbHndl, wMciDeviceID)) Then Exit Function
                                If (MCI_Close(CbHndl)) Then Exit Function
                        End If
    
                End Select
    
            Case %MM_MCINOTIFY  'Film fertig abgespielt
                Select Case CbWParam
                    Case %MCI_NOTIFY_SUCCESSFUL
                        If MCI_Status(wMciDeviceID, %MCI_STATUS_MODE) <> Lo(Word,&hFFFF) Then Call MCI_Close(CbHndl)
                        Control Set Text CbHndl, %IDC_VIDEO, "End of movie"
    
                    Case %MCI_NOTIFY_ABORTED
                    Case %MCI_NOTIFY_SUPERSEDED
                    Case %MCI_NOTIFY_FAILURE
    
                End Select
    
    
            Case %WM_COMMAND    ' Process control notifications
                Select Case As Long CbCtl
    
                    Case %IDC_PLAY
                        If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                            Control Get Text CbHndl,%IDC_PATH To sPath
                            Control Handle CbHndl, %IDC_VIDEO To hVideo
    
                            If (MCI_OPEN(CbHndl, sPath, "MPEGVideo")) Then Exit Function
    
                            'Position of the Control, only left and top necessary
                            rectLbl.nLeft   = 20
                            rectLbl.nTop    = 35
    
                            If (MCI_Put(CbHndl, hVideo, wMciDeviceID, rectLbl)) Then Exit Function
                            If (MCI_PlayMovie(CbHndl, wMciDeviceID)) Then Exit Function
    
                        End If
    
                    Case %IDC_STOP
                        If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                            If MCI_Status(wMciDeviceID, %MCI_STATUS_MODE) <> Lo(Word,&hFFFF) Then
                                If (MCI_Stop(CbHndl, wMciDeviceID)) Then Exit Function
                                If (MCI_Close(CbHndl)) Then Exit Function
                                Control Set Text CbHndl, %IDC_VIDEO, "Stop by user"
                            End If
                        End If
    
                End Select
        End Select
    End Function
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    Function ShowMAINFRAME(ByVal hParent As Dword) As Long
        Local lRslt As Long
    #PBForms Begin Dialog %IDD_MAINFRAME->->
        Local hDlg  As Dword
    
        Dialog New hParent, "Video Player", 70, 70, 408, 324, %WS_POPUP Or %WS_BORDER Or %WS_DLGFRAME Or %WS_SYSMENU Or %WS_MINIMIZEBOX Or _
            %WS_CLIPSIBLINGS Or %WS_VISIBLE Or %DS_MODALFRAME Or %DS_3DLOOK Or %DS_NOFAILCREATE Or %DS_SETFONT, %WS_EX_WINDOWEDGE Or _
            %WS_EX_CONTROLPARENT Or %WS_EX_LEFT Or %WS_EX_LTRREADING Or %WS_EX_RIGHTSCROLLBAR, To hDlg
        Control Add TextBox, hDlg, %IDC_PATH, "L:\MCI_MPEG\willtell.mpeg", 0, 15, 315, 12
        Control Add Label,   hDlg, %IDC_VIDEO, "", 20, 35, 355, 260, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER Or %WS_CLIPSIBLINGS Or %WS_CLIPCHILDREN Or _
            %SS_LEFT, %WS_EX_CLIENTEDGE Or %WS_EX_LEFT Or %WS_EX_LTRREADING
        Control Add Button,  hDlg, %IDC_PLAY, "&Play", 319, 15, 41, 15
        Control Add Button,  hDlg, %IDC_STOP, "&Stop", 366, 15, 41, 15
    #PBForms End Dialog
        Dialog Show Modal hDlg, Call ShowMAINFRAMEProc To lRslt
    #PBForms Begin CleanUp %IDD_MAINFRAME
    #PBForms End CleanUp
        Function = lRslt
    End Function
    '------------------------------------------------------------------------------
    Maybe it's a help for you

    ----------------
    Rudolf Fürstauer



    [This message has been edited by Rudolf Fürstauer (edited May 01, 2006).]
    ----------------
    Rudolf Fürstauer

    Comment


    • #3
      Dear Rudolf,

      thank you kindly for your help. I'll be figuring out where exactly I went wrong (was it really just the styles?).

      I did notice that your method seems not to actually put the video into the label control but to a set position on screen. Is that correct?

      I've browsed the MCI reference on MSDN for what seems like hours and can't figure out how to pause and unpause a file using the MciSendCommand function. Mixing this command with an MCISendString "pause..." command doesn't really do the trick. Using %MCI_PAUSE in the MciSendCommand command seems to stop the movie entirely without resuming being possible.

      The ultimate goal is to write a tool for helping with subtitling DVD bonus features that'll test-sync text subtitles to a video file. Just in case you were wondering what the heck I needed this for ;-)

      Thanks again,

      Oliver

      ------------------


      [This message has been edited by Oliver Copp (edited May 01, 2006).]

      Comment


      • #4
        Oliver,

        I do not know if this will help you or answer your question.
        To be honest, I am not very fond of having to wade through code
        created by a "code generator/forms designer" software. The two
        lines below show what my custom MCI control uses to put the video
        for a media source into a control

        Code:
            mciSendString "window " + @lptr.title + " handle " + format$(@lptr.hwndvideo), "", 0, 0 '"@lptr.title" is where my control stores the alias it opened the media file with
                                                                                                    '"@lptr.hwndvideo" is where my control stores the window handle for the control used to display the video  
            mcisendstring "put " + @lptr.title + " destination", "", 0, 0 'this line makes MCI adjust the video display to the boundaries of the control displaying the image. MCI stretches or shrinks the
                                                                          'video display as necessary
        EDIT: the " put [...] destination" line is not necessary. If it is not sent to MCI,
        the video will be displayed in the control if the first line is sent, except the video will
        be displayed with its intrinsic x/y ratio. My personal preference is for the
        video to fill the whole control, which is why my control also sends the second line.

        ------------------




        [This message has been edited by Clay Clear (edited May 02, 2006).]

        Comment


        • #5
          Clay,

          I apologize if my posting working code offended or inconvenienced you in any way.

          I was under the impression that it's always best to post working code that illustrates the problem and is compilable as is.

          Thank you very much for your help, though. I'll try it out immediately.

          Thanks,

          Oliver

          ------------------

          Comment


          • #6
            No need to feel offended. I was not criticizing those who use
            forms desginer software, the software itself, or posting code
            from such designers. I was only explaining why I had not read through
            your code, but offered something that might still be of use, anyway.
            My dislike for forms designer stuff is a quirk of mine, not something
            for me to diss others about.

            And, no, I do not feel offended at your words. I am only explaining
            for the sake of everybody who uses forms designe software, so nobody
            else also feels offended at my words.


            ------------------

            Comment

            Working...
            X