Jump to content

How to seek video position


ajit
 Share

Recommended Posts

Hi

This is based on UDF submitted by ludocus.

However much i tried, i could not use a slider to seek the video position. Could someone help me with it?

Thanks in anticipation

Ajit

Herebelow the code:

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.11.7 (beta)

Author: ludocus

Script Function:

Template AutoIt script.

#ce ----------------------------------------------------------------------------

#include <GUIConstants.au3>

global $mov, $tAlias

$hVideo = GUICreate("Test Video Player", 340, 280)

$hPlay = GUICtrlCreateButton("Play", 10, 255, 60, 20)

$hPause = GUICtrlCreateButton("Pause", 75, 255, 60, 20)

$hLoad = GUICtrlCreateButton("Load", 140, 255, 60, 20)

$position = GUICtrlCreateSlider(205, 255, 130, 20) ; slider to seek position

GUISetState()

While 1

Switch GUIGetMsg()

Case $GUI_EVENT_CLOSE

_MovieClose($mov)

Exit

Case $position

Case $hPlay

_MoviePlay($mov)

Case $hPause

_MoviePause($mov)

Case $hLoad

$sFile = FileOpenDialog("Open", "", "All Files (*.*)", 1)

if not $sFile = '' Then

$mov = _MovieOpen($sFile, $hVideo, 10, 10, 320, 240 )

EndIf

EndSwitch

WEnd

; Script Start - Add your code below here

Func mciSendString($string)

Local $iRet

$iRet = DllCall("winmm.dll", "int", "mciSendStringA", "str", $string, "str", "", "int", 65534, "hwnd", 0)

If Not @error Then Return $iRet[2]

EndFunc ;==>mciSendString

Func _MovieOpen($pFile, $pHwnd, $pTop, $pLeft, $pWidth, $pHeight, $pAlias='')

if $pAlias = '' then $pAlias = RandomStr(10)

mciSendString("close "&$pAlias)

if Not @error Then

mciSendString("open " & FileGetShortName($pFile) & " alias "&$pAlias)

mciSendString("window "&$pAlias&" handle " & Number($pHwnd))

mciSendString("put "&$pAlias&" destination at "&$pTop&' '&$pLeft&' '&$pWidth&' '&$pHeight)

return $pAlias

Else

return 0

EndIf

EndFunc

func _MovieClose($hAlias)

return mciSendString("close "&$hAlias)

EndFunc

func _MoviePause($rAlias)

return mciSendString("pause "&$rAlias)

EndFunc

func _MovieStop($jAlias)

return mciSendString("seek " &$jAlias& " to start")

EndFunc

func _MoviePlay($sAlias)

mciSendString("set Test_Video time format milliseconds")

If mciSendString("status "&$sAlias&" position") = mciSendString("status "&$sAlias&" length") Then mciSendString("seek "&$sAlias&" to start")

mciSendString("play "&$sAlias)

return 1

EndFunc

func _MoviePos($tAlias)

$sReturn = mciSendString("status "&$tAlias&" position")

if @error then return 0

return $sReturn

EndFunc

func _MovieLength($tAlias)

$tReturn = mciSendString("status "&$tAlias&" length")

if @error then return 0

return $tReturn

EndFunc

func _MovieSeek($sSnd_id, $iHour, $iMin, $iSec)

Local $iMs = 0

Local $iRet

mciSendString("set " & FileGetShortName($sSnd_id) & " time format miliseconds")

$iMs += $iSec * 1000

$iMs += $iMin * 60 * 1000

$iMs += $iHour * 60 * 60 * 1000

$iRet = mciSendString("seek " &$sSnd_id& " to " & $iMs)

If $iRet = 0 Then

Return 1

Else

Return SetError(1, 0, 0)

EndIf

EndFunc

func _MovieStatus($kAlias)

Return mciSendString("status "&$kAlias&" mode")

EndFunc

Func RandomStr($len)

Local $string

For $iCurrentPos = 1 To $len

$string &= Chr(Random(97, 122, 1))

Next

Return $string

EndFunc

movie.au3

Edited by ajit
Link to comment
Share on other sites

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.11.7 (beta)
    Author: ludocus
    
    Script Function:
    Template AutoIt script.
    
#ce ----------------------------------------------------------------------------

#include <GUIConstants.au3>
Global $mov, $tAlias, $iLength = 0


$hVideo = GUICreate("Test Video Player", 340, 280)
$hPlay = GUICtrlCreateButton("Play", 10, 255, 60, 20)
$hPause = GUICtrlCreateButton("Pause", 75, 255, 60, 20)
$hLoad = GUICtrlCreateButton("Load", 140, 255, 60, 20)
$position = GUICtrlCreateSlider(205, 255, 130, 20) ; slider to seek position
GUICtrlSetLimit(-1, 100)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _MovieClose($mov)
            Exit
        Case $position
            Local $iPos, $iTotalMs
            
            If $iLength > 0 Then
                $iPos = GUICtrlRead($position)/100
                $iTotalMs = Int($iPos*$iLength)
                _MovieSeek($mov, $iTotalMs)
            EndIf
            
        Case $hPlay
            _MoviePlay($mov)
        Case $hPause
            _MoviePause($mov)
        Case $hLoad
            $sFile = FileOpenDialog("Open", "", "All Files (*.*)", 1)
            If $sFile = '' Then
                $iLength = 0
            Else
                $mov = _MovieOpen($sFile, $hVideo, 10, 10, 320, 240)
                $iLength = _MovieLength($mov)
            EndIf
    EndSwitch
WEnd



; Script Start - Add your code below here
Func mciSendString($string)
    Local $iRet
    $iRet = DllCall("winmm.dll", "int", "mciSendStringA", "str", $string, "str", "", "int", 65534, "hwnd", 0)
    If Not @error Then Return $iRet[2]
EndFunc   ;==>mciSendString

Func _MovieOpen($pFile, $pHwnd, $pTop, $pLeft, $pWidth, $pHeight, $pAlias = '')
    If $pAlias = '' Then $pAlias = RandomStr(10)
    mciSendString("close " & $pAlias)
    If Not @error Then
        mciSendString("open " & FileGetShortName($pFile) & " alias " & $pAlias)
        mciSendString("window " & $pAlias & " handle " & Number($pHwnd))
        mciSendString("put " & $pAlias & " destination at " & $pTop & ' ' & $pLeft & ' ' & $pWidth & ' ' & $pHeight)
        Return $pAlias
    Else
        Return 0
    EndIf
EndFunc   ;==>_MovieOpen

Func _MovieClose($hAlias)
    Return mciSendString("close " & $hAlias)
EndFunc   ;==>_MovieClose

Func _MoviePause($rAlias)
    Return mciSendString("pause " & $rAlias)
EndFunc   ;==>_MoviePause

Func _MovieStop($jAlias)
    Return mciSendString("seek " & $jAlias & " to start")
EndFunc   ;==>_MovieStop


Func _MoviePlay($sAlias)
    mciSendString("set Test_Video time format milliseconds")
    If mciSendString("status " & $sAlias & " position") = mciSendString("status " & $sAlias & " length") Then mciSendString("seek " & $sAlias & " to start")
    mciSendString("play " & $sAlias)
    Return 1
EndFunc   ;==>_MoviePlay

Func _MoviePos($tAlias)
    $sReturn = mciSendString("status " & $tAlias & " position")
    If @error Then Return 0
    Return $sReturn
EndFunc   ;==>_MoviePos

Func _MovieLength($tAlias)
    $tReturn = mciSendString("status " & $tAlias & " length")
    If @error Then Return 0
    Return $tReturn
EndFunc   ;==>_MovieLength

Func _MovieSeek($sSnd_id, $iMs)
    Local $iRet
    mciSendString("set " & FileGetShortName($sSnd_id) & " time format miliseconds")
    $iRet = mciSendString("seek " & $sSnd_id & " to " & $iMs)
    If $iRet = 0 Then
        Return 1
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_MovieSeek

Func _MovieStatus($kAlias)
    Return mciSendString("status " & $kAlias & " mode")
EndFunc   ;==>_MovieStatus


Func RandomStr($len)
    Local $string
    For $iCurrentPos = 1 To $len
        $string &= Chr(Random(97, 122, 1))
    Next
    Return $string
EndFunc   ;==>RandomStr

Edited by Authenticity
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...