 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Trubbleguy
Joined: 20 Jan 2007 Posts: 73 Location: Melbourne
|
Posted: Wed Jun 25, 2008 2:18 pm Post subject: vidplay(FileName,x,y,w,h,loop,ontop) function |
|
|
I finally hit on an easy way to set a video at a required x,y,w and h location onscreen with a function.
There is no FF, RW or Pause, just load, play, stop, location, size, Loop and AlwaysOnTop
It does depend on Codecs installed and wrong Codecs give weird results.
the first code box is the function.
use #include vidplay.ahk in your main code, so copy and save the first box to vidplay.ahk
| Code: | ;; Command Syntax
;; vidplay(filename,x,y,w,h,Repeat,alwaysontop) ;play move,size,loop ,always on top
;; vidstop() ;stop and close
vidplay( mmedia=" " , xx="1" , yy="1" , ww="Auto" , hh="Auto", repeat="0" ,ontop="0" ) {
DllCall("winmm\mciSendStringA", "str", "close mmedia notify", "Uint", 0, "Uint", 0, "Uint", hAHK) ;remove this line if you always want to close the current file with the vidstop() command first
DllCall("winmm\mciSendStringA", "str", " open """ . mmedia . """ alias mmedia ", "Uint", 0, "Uint", 0, "Uint", 0)
if repeat
DllCall("winmm\mciSendStringA", "str", " play mmedia repeat", "Uint", 0, "Uint", 0, "Uint", hAHK)
else
DllCall("winmm\mciSendStringA", "str", " play mmedia ", "Uint", 0, "Uint", 0, "Uint", hAHK)
if hh not contains Auto
winmove,%mmedia%,,xx,yy,ww,hh-12 ;hh-12 is to allow for removal of header to fit video correctly
else
{
WinGetPos,,,ww1,hh1,%mmedia%
winmove,%mmedia%,,xx,yy,ww1,hh1-19 ;hh1-19 is to allow for removal of header to fit video correctly when auto used
}
If ontop=1
WinSet,AlwaysOnTop,On,%mmedia%
WinSet, Style, -0x800000 ,%mmedia% ;remove Header from video window
}
Vidstop(){
DllCall("winmm\mciSendStringA", "str", "close mmedia notify", "Uint", 0, "Uint", 0, "Uint", hAHK)
}
|
The second bit of code below is a very basic example on its use.
| Code: | #SingleInstance Force
#Include vidplay.ahk
file=c:\somefolder\somevideofile.wmv
F5:: ;play the video and and move it to x10 y10 using default video size
vidplay(file,10,10)
Return
F6:: ;play the video and and move it to x10 y10 using new video size and make it loop and ONTOP
vidplay(file,10,10,320,240,1,1)
Return
f7::
vidstop() ;use this command to close current playing video before getting a new filename
FileSelectFile, file ,1, C:\somefolder\, Select your file,*.avi;*.mpg;*.wmv
vidplay(file,10,10,"Auto","Auto",1,1) ;play video in loop and AlwaysOnTop with default video size
Return
F8:: ;stop and close the video
vidstop() ;use this command to close any playing video
Return
|
_________________

Last edited by Trubbleguy on Thu Jun 26, 2008 3:47 pm; edited 1 time in total |
|
| Back to top |
|
 |
Trubbleguy
Joined: 20 Jan 2007 Posts: 73 Location: Melbourne
|
Posted: Thu Jun 26, 2008 1:07 pm Post subject: |
|
|
Nearly 24hrs , 49 views, and not a single comment on if it works for you or not!!!!! _________________
 |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 903 Location: The Interwebs
|
Posted: Thu Jun 26, 2008 1:14 pm Post subject: |
|
|
Works similarly to the Media_ functions... Some video it works perfectly, many it plays fine except there's no sound, and some it plays in like 2 or 3x speed with no sound. All avi, just using different codecs I suppose.
Just a limitation of the DllCalls... |
|
| Back to top |
|
 |
garry
Joined: 19 Apr 2005 Posts: 1030 Location: switzerland
|
Posted: Thu Jun 26, 2008 3:43 pm Post subject: |
|
|
Thank you Trubbleguy, I like it
works fine |
|
| Back to top |
|
 |
soggos
Joined: 27 Mar 2008 Posts: 30
|
Posted: Sat Aug 09, 2008 8:13 pm Post subject: kool |
|
|
hello
very good
it's possible to modification the speed? |
|
| Back to top |
|
 |
BoBo² Guest
|
Posted: Sun Aug 10, 2008 12:02 pm Post subject: |
|
|
Well, I like it too
Just in case others wanna have a try as well: [Sample movies] |
|
| Back to top |
|
 |
soggos
Joined: 27 Mar 2008 Posts: 30
|
Posted: Tue Aug 12, 2008 7:48 pm Post subject: |
|
|
good
| Quote: | | Just in case others wanna have a try as well: [Sample movies] | but i want to play in direct
with the:
Functions to handle multimedia files by Fincs <fernandoincs@hotmail.com>
a have made that:
| Code: | if %0% != 0
{
SelectedFileName = %1%
}
ELSE
SelectedFileName =
gosub console
if %0% != 0
{
h := Media_Open(SelectedFileName)
SplitPath, SelectedFileName, name, dir, ext, name_no_ext, drive
Media_ToHHMMSS(Media_Length(h), hh, mm, ss)
TEMPS_TOTAL = %hh%:%mm%:%ss%
len := Media_Length(h)
guicontrol ,,TEMPS_POSI2, %len%
guicontrol ,,TEMPS_POSI1, 0
guicontrol ,,NOMTITRE, %dir% %name_no_ext%
Media_Play(h)
}
SetTimer ,AFFICHE_TEMPS,100
return
; ------------------------------------------------------------------
CONSOLE:
Gui, Font, S8 Bold cGreen, Verdana
Gui, Add, Text, x6 y7 w320 h20 vNOMTITRE +Center,
Gui, Add, Text, x326 y7 w60 h20 vTEMPS_PASSE +Center, 0
Gui, Add, Text, x116 y27 w80 h20 vTEMPS_PASSE2 +Right, 10
Gui, Font, S8 Bold cBlack, Verdana
Gui, Add, Text, x386 y7 w60 h20 , %TEMPS_TOTAL%
Gui, Font, S7 Norm cBlack, Verdana
Gui, Add, Button, x226 y67 w100 h20 gJOUER, &JOUER
Gui, Add, Button, x326 y67 w100 h20 gPAUSER, &PAUSE
Gui, Add, Button, x326 y47 w100 h20 gSTOPPER, &STOPPER
Gui, Add, Button, x36 y47 w80 h20 gBOUCLE1, &Deb Boucle
Gui, Add, Button, x36 y67 w80 h20 gBOUCLE2, &Faire Boucle
Gui, Add, Edit, x116 y47 w80 h20 vTEMPS_POSI1 +Right,
Gui, Add, Edit, x116 y67 w80 h20 vTEMPS_POSI2 +Right,
Gui, Add, Edit, x226 y47 w100 h20 vTEMPS_POSIN,
Gui, Add, Progress, x11 y97 w520 h10 cBlue vMyProgress,
Gui, Add, Slider, x6 y102 w530 h20 Range0-%len% Page1000 TickInterval500 NoTicks vMyProgress2 gALLER, 0
Gui, Add, Button, x196 y47 w20 h20 gRAZBOUCLE1, 0
Gui, Add, Button, x36 y87 w160 h10 gRAZBOUCLE2, fin
Gui, Add, Button, x6 y47 w30 h20 gALLER1, aller
Gui, Add, Button, x6 y67 w30 h20 gALLER2, aller
Gui, Add, Button, x16 y127 w250 h20 gALLERMOINS, -
Gui, Add, Button, x276 y127 w250 h20 gALLERPLUS, +
Gui, Add, Text, x306 y27 w120 h20 vSTATUSdeLECTURE +Center, %STATUSdeLECTURE%
Gui, Add, Checkbox, x226 y27 w80 h20 vFAIREBOUCLE, &BOUCLE
Gui, Show, h195 w562,, %SelectedFileName%
Return
; ------------------------------------------------------------------
AFFICHE_TEMPS:
pos := Media_Position(h)
guicontrol ,,TEMPS_PASSE2, %pos%
GuiControl,, TEMPS_POSIN, %pos%
combien := ( pos * 100 ) / len
GuiControl,, MyProgress, %combien%
;GuiControl,, MyProgress2, %combien%
az := Media_Status(h)
guicontrol ,,STATUSdeLECTURE, %az%
guiControlGet ,FAIREBOUCLE
if FAIREBOUCLE = 1
goto BOUCLER
return
; ------------------------------------------------------------------
BOUCLER:
settimer , AFFICHE_TEMPS, off
guiControlGet ,TEMPS_POSI1
Media_Seek(h, TEMPS_POSI1, False)
Media_Play(h)
loop
{
guiControlGet ,FAIREBOUCLE
if FAIREBOUCLE = 0
{
settimer , AFFICHE_TEMPS, on
break
}
guicontrol ,,STATUSdeLECTURE, en BOUCLE
guiControlGet ,TEMPS_POSI1
guiControlGet ,TEMPS_POSI2
pos := Media_Position(h)
If(pos >= TEMPS_POSI2)
{
Media_Seek(h, TEMPS_POSI1, False)
}
else
{
guicontrol ,,TEMPS_PASSE2, %pos%
combien := ( pos * 100 ) / len
GuiControl ,, MyProgress, %combien%
}
}
return
; ------------------------------------------------------------------
ALLER:
guiControlGet ,MyProgress2
guicontrol ,,TEMPS_POSIN, %MyProgress2%
Media_Seek(h, MyProgress2, False)
return
; ------------------------------------------------------------------
BOUCLE1:
pos := Media_Position(h)
guicontrol ,,TEMPS_POSI1, %pos%
return
; -----------------------------------------------------------------
BOUCLE2:
pos := Media_Position(h)
guicontrol ,,TEMPS_POSI2, %pos%
guiControl ,,FAIREBOUCLE,1
return
; ------------------------------------------------------------------
RAZBOUCLE1:
guicontrol ,,TEMPS_POSI1, 0
return
RAZBOUCLE2:
len := Media_Length(h)
guicontrol ,,TEMPS_POSI2, %len%
return
; ------------------------------------------------------------------
ALLER1:
guiControlGet ,TEMPS_POSI1
Media_Seek(h, TEMPS_POSI1, False)
return
ALLER2:
guiControlGet ,TEMPS_POSI2
Media_Seek(h, TEMPS_POSI2, False)
return
; ------------------------------------------------------------------
ALLERPLUS:
Media_Seek(h, 100, True)
pos := Media_Position(h)
guicontrol ,,TEMPS_POSIN, %pos%
return
ALLERMOINS:
Media_Seek(h, -100, True)
pos := Media_Position(h)
guicontrol ,,TEMPS_POSIN, %pos%
return
; ------------------------------------------------------------------
JOUER:
;guiControlGet ,TEMPS_POSIN
;guiControlGet ,MyProgress2
;Media_Seek(h, TEMPS_POSIN, False)
Media_Play(h)
return
STOPPER:
Media_Stop(h)
return
PAUSER:
Media_Pause(h)
return
PAUSERR:
Media_Resume(h)
return
; =======================================================================================
; ======================================================================================
; ... . (drag&drop, rezise ...
GuiDropFiles: ; Support drag & drop.
compte =
; StringSplit, Array, A_GuiEvent, .
Loop, parse, A_GuiEvent, `n
{
SelectedFileName = %A_LoopField% ; Get the first file only (in case there's more than one).
compte+=1
; break
}
if compte >1
{
FileList = %A_GuiEvent%
Sort, FileList
;Loop, parse, FileList, `n
;GuiControl ,,
;MsgBox File number %A_Index% is:`n%A_LoopField%.
GuiControl,, MyEdit1, %FileList% ; Put the text into the control.
; Gosub LISTEdeFICHIERS
}
else
{
Loop, parse, A_GuiEvent, `n
{
;Gui , Show, , > %A_GuiEvent%
;CurrentFileName = %A_GuiEvent%
Gosub NOUVEAU
; SelectedFileName = %A_LoopField% ; Get the first file only (in case there's more than one).
break
}
; GuiControl,, MyEdit1, %SelectedFileName% ; Put the text into the control.
}
return
; ------------------------------------------------------------------
NOUVEAU:
;Media_Close(h)
gui destroy
;msgbox ,4096,, %SelectedFileName%
h :=Media_Open(SelectedFileName)
Media_Play(h)
len := Media_Length(h)
Media_ToHHMMSS(Media_Length(h), hh, mm, ss)
TEMPS_TOTAL = %hh%:%mm%:%ss%
gosub CONSOLE
SplitPath, SelectedFileName, name, dir, ext, name_no_ext, drive
guicontrol ,,NOMTITRE, %name_no_ext%
guicontrol ,,TEMPS_POSI2, %len%
guicontrol ,,TEMPS_POSI1, 0
guicontrol ,,MyProgress2, 0
guicontrol ,,TEMPS_TOTAL, %TEMPS_TOTAL%
return
F5::
reload
return
F7::
ExitApp
return
GuiClose:
ExitApp
; ----------------------------------------------------------------------------------;;
;; AutoHotkey Version: 1.0.47.04
;; Language: Anyone
;; Author: Fincs <fernandoincs@hotmail.com>
;:
;; Script Function:
;; Functions to handle multimedia files
;;
;: Title: Media.ahk - Multimedia functions to use with AutoHotkey
;
; Function: Media_Open
; Description:
; Opens a multimedia file for use with other multimedia functions
; Syntax: Media_Open(File[, Alias=""])
; Parameters:
; File - The multimedia file
; Alias - (optional) A name such as media1, if you do not
; specify one it is automatically generated
; Return Value:
; The multimedia handle or a 0 to indicate failure
; Example:
; file:mediaopenclose-example.ahk
;Media_Play(h)
;h := Media_Open("I:\2.WMV")
; -----------------------------------------------------------------------------------
Media_Open(File, Alias=""){
Static SoundNumber = 0
IfNotExist, %File%
{
ErrorLevel = -2
Return 0
}
If Alias =
{
SoundNumber ++
Alias = AutoHotkey%SoundNumber%
}
;Loop, %Param1%
; File_Short = %A_LoopFileShortPath%
ErrorLevel := _mciExecute("open """ File """ alias " Alias)
Return Alias
}
;
; Function: Media_Close
; Description:
; Closes a multimedia file
; Syntax: Media_Close(MediaHandle)
; Parameters:
; MediaHandle - Multimedia handle returned by [url=Media_Open.htm]Media_Open()[/url]
; Return Value:
; Return value returned by MCI
; Example:
; file:mediaopenclose-example.ahk
;
Media_Close(MediaHandle){
Return _mciExecute("close " MediaHandle)
}
;
; Function: Media_Play
; Description:
; Plays a multimedia file from the current position (beginning is the default)
; Syntax: Media_Play(MediaHandle[, Wait=0])
; Parameters:
; MediaHandle - Multimedia handle returned by [url=Media_Open.htm]Media_Open()[/url]
; Wait - (optional) If TRUE the script will wait for the multimedia file to finish before continuing.
; Else the script will continue while the multimedia file is playing.
; Return Value:
; Return value returned by MCI
; Example:
; file:playonesecond-example.ahk
;
Media_Play(MediaHandle, Wait=0){
If(Wait <> 0 AND Wait <> 1)
Return -2
If Wait = 1
Return _mciExecute("play " MediaHandle " wait")
Else
Return _mciExecute("play " MediaHandle)
}
;
; Function: Media_Stop
; Description:
; Stops the multimedia file
; Syntax: Media_Stop(MediaHandle)
; Parameters:
; MediaHandle - Multimedia handle returned by [url=Media_Open.htm]Media_Open()[/url]
; Return Value:
; Return value returned by MCI
; Example:
; file:playonesecond-example.ahk
;
Media_Stop(MediaHandle){
ret := _mciExecute("seek " MediaHandle " to start")
ret := ret && _mciExecute("stop " MediaHandle)
Return ret
}
;
; Function: Media_Pause
; Description:
; Pauses the multimedia file
; Syntax: Media_Pause(MediaHandle)
; Parameters:
; MediaHandle - Multimedia handle returned by [url=Media_Open.htm]Media_Open()[/url]
; Return Value:
; Return value returned by MCI
; Example:
; file:playonesecond-example.ahk
;
Media_Pause(MediaHandle){
Return _mciExecute("pause " MediaHandle)
}
;
; Function: Media_Resume
; Description:
; Resumes the multimedia file after being paused
; Syntax: Media_Resume(MediaHandle)
; Parameters:
; MediaHandle - Multimedia handle returned by [url=Media_Open.htm]Media_Open()[/url]
; Return Value:
; Return value returned by MCI
;
Media_Resume(MediaHandle){
Return _mciExecute("resume " MediaHandle)
}
;
; Function: Media_Length
; Description:
; Returns the length of the multimedia file
; Syntax: Media_Length(MediaHandle)
; Parameters:
; MediaHandle - Multimedia handle returned by [url=Media_Open.htm]Media_Open()[/url]
; Return Value:
; Length of the multimedia file in milliseconds
; Example:
; file:fileinfo-example.ahk
;
Media_Length(MediaHandle){
rc := _mciSendString("set time format milliseconds", dummy)
If !rc
Return -rc
_mciSendString("status " MediaHandle " length", ret)
Return ret
}
;
; Function: Media_Seek
; Description:
; Seeks the multimedia file to a specified time
; Syntax: Media_Seek(MediaHandle, Position[, Relative=0])
; Parameters:
; MediaHandle - Multimedia handle returned by [url=Media_Open.htm]Media_Open()[/url]
; Pos - Time to seek to in milliseconds
; Relative - (Optional) If specified, the position specified is relative
; to the current position
; Return Value:
; Return value returned by MCI
; Example:
; file:playnseek-example.ahk
;
Media_Seek(MediaHandle, Position, Relative=0){
rc := _mciSendString("set time format milliseconds", dummy)
_mciSendString("status " MediaHandle " mode", stat)
If stat = playing
_mciExecute("pause " MediaHandle)
If !rc
Return -rc
_mciSendString("status " MediaHandle " position", cpos)
_mciSendString("status " MediaHandle " length", length)
If Relative = 1
cpos += Position
Else
cpos := Position
If cpos > %length%
cpos = %length%
If cpos < 0
cpos = 0
ret := _mciExecute("seek " MediaHandle " to " cpos)
If stat = playing
_mciExecute("play " MediaHandle)
Return ret
}
;
; Function: Media_Status
; Description:
; Returns the status of the multimedia file
; Syntax: Media_Status(MediaHandle)
; Parameters:
; MediaHandle - Multimedia handle returned by [url=Media_Open.htm]Media_Open()[/url]
; Return Value:
; Current status of the multimedia file
; Remarks:
; All devices can return the "not ready", "paused", "playing", and "stopped" values.
; Some devices can return the additional "open", "parked", "recording", and "seeking" values.(MSDN)
;
Media_Status(MediaHandle){
_mciSendString("status " MediaHandle " mode", ret)
Return ret
}
;
; Function: Media_Position
; Description:
; Returns the current position of the multimedia file
; Syntax: Media_Position(MediaHandle)
; Parameters:
; MediaHandle - Multimedia handle returned by [url=Media_Open.htm]Media_Open()[/url]
; Return Value:
; Position of the multimedia file in milliseconds
; Example:
; file:mediaplayer-example.ahk
;
Media_Position(MediaHandle){
rc := _mciSendString("set time format milliseconds", dummy)
If !rc
Return -rc
_mciSendString("status " MediaHandle " position", ret)
Return ret
}
;===============================================================================
;
; Function: Media_ToMilliseconds
; Description:
; Converts the specified hour, minute and second into a valid milliseconds timestamp
; Syntax: Media_ToMilliseconds(Hour, Min, Sec)
; Parameters:
; Hour, Min, Sec - Position to convert to milliseconds
; Return Value:
; The specified position converted to milliseconds
;
Media_ToMilliseconds(Hour, Min, Sec){
milli := Sec * 1000
milli += (Min * 60) * 1000
milli += (Hour * 3600) * 1000
Return milli
}
;
; Function: Media_ToHHMMSS
; Description:
; Converts the specified milliseconds timestamp to a (Hour, Min, Sec) timestamp
; Syntax: Media_ToHHMMSS(milliseconds, ByRef Hour, ByRef Min, ByRef Sec)
; Parameters:
; milliseconds - Milliseconds timestamp to convert
; (ByRef) Hour, Min, Sec - Output variables where store the converted timestamp
; Example:
; file:fileinfo-example.ahk
;
Media_ToHHMMSS(milliseconds, ByRef Hour, ByRef Min, ByRef Sec){
milliseconds //= 1000
Sec := Mod(milliseconds, 60)
milliseconds //= 60
Min := Mod(milliseconds, 60)
milliseconds //= 60
Hour := Mod(milliseconds, 60)
}
_mciExecute(string){
Return DllCall("winmm.dll\mciExecute", "str", string, "Cdecl Int")
}
_mciSendString(string, ByRef output, handle=0){
VarSetCapacity(output, 36, 0)
ret := DllCall("winmm.dll\mciSendStringA", "str", string, "str", output, "int", 36, "uint", 0, "Cdecl Int")
If ErrorLevel
Return -ErrorLevel
Return ret
}
|
very good for sampling:)
[drag&drop a file into]
but how to do for modifi the speed with slider?
and it's possible to up or down the volume of this song [not of the master just this player]?
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|