Hey, is it possible to make sound loop?
If so how?
Here's one way to do it. For the
MCI_Play function, include
from and
to flags in the
p_Flags parameter and specify a callback function name in the
p_Callback parameter.
In the following example, the script will loop any media file from 25000 to 35000 (from 25 seconds to 35 seconds) until the Stop button is pressed. To loop the entire media file just get rid of the
from and
to flags.
#NoEnv
#SingleInstance Force
gui Margin,0,0
gui Add,Button,w70 h35,Open
gui Add,Button,x+0 wp hp,Play
gui Add,Button,x+0 wp hp,Pause
gui Add,Button,x+0 wp hp,Stop
gui Show
gosub ButtonOpen
return
GUIEscape:
GUIClose:
if Open
MCI_Close(hMedia)
ExitApp
ButtonOpen:
if Open
MCI_Close(hMedia)
if not DefaultFolder
DefaultFolder:=A_MyDocuments
gui +OwnDialogs
FileSelectFile, MediaFile,1,%DefaultFolder%,Choose a media file
if (MediaFile="")
return
SplitPath MediaFile,,DefaultFolder
hMedia:=MCI_Open(MediaFile)
if Not hMedia
{
MsgBox Error opening media file
return
}
Open:=True
gosub ButtonPlay
return
ButtonPlay:
if Open
{
Status:=MCI_Status(hMedia)
if (Status="Stopped")
gosub Play
else
if (Status="Paused")
MCI_Resume(hMedia)
}
return
Play:
MCI_Play(hMedia,"from 25000 to 35000","NotifyEndOfPlay")
return
ButtonPause:
if Open
{
Status:=MCI_Status(hMedia)
if (Status="Playing")
MCI_Pause(hMedia)
else
if (Status="Paused")
MCI_Resume(hMedia)
}
return
ButtonStop:
if Open
{
MCI_Stop(hMedia)
MCI_Seek(hMedia,0)
}
return
NotifyEndOfPlay(Flag)
{
Global
;;;;; Critical
if (Flag=1) ;-- 1=play ended normally
gosub Play
}
#include MCI.ahk
The only problem that I ran into is that callback routine gets lost (returns a to-be-determined value) if the loop period is too short (less than 3 or 4 seconds?). Reliability can be improved by adding a
Critical statement to the callback function.
I hope this helps.