Code: Select all
#Register_Window = 34230
If OpenLibrary(0,"msvfw32.dll")
*MCIWndCreate = GetFunction(0,"MCIWndCreate")
EndIf
Structure MCIOpenParams
FileName.s
Alias.s
EndStructure
Structure MCIPlayParams
Alias.s
FromPos.l
ToPos.l
EndStructure
Global play.MCIPlayParams
Global MCIMsg.l = 0
Procedure.s MCIGetError(Error.l)
err.s = Space(255)
mciGetErrorString_(Error,@err,255)
ProcedureReturn err
EndProcedure
Procedure.l MCIOpen(Alias.s, FileName.s)
Error = mciSendString_("open "+Chr(34)+FileName+Chr(34)+" type mpegvideo alias "+Alias,0,0,0)
ProcedureReturn Error
EndProcedure
Procedure.l MCIPause(Alias.s)
Error = mciSendString_("pause "+Alias,0,0,0)
ProcedureReturn Error
EndProcedure
Procedure.l MCIPlay(Alias.s, FromPos.l, ToPos.l)
mciString.s = "play "+Alias
If FromPos
mciString + " from "+Str(FromPos)
If ToPos
mciString + " to "+Str(ToPos)
EndIf
EndIf
Error = mciSendString_(mciString,0,0,0)
ProcedureReturn Error
EndProcedure
Procedure MCICallbackThread(*p.MCIOpenParams)
Repeat
Select MCIMsg
Case #MCI_PLAY
Error = MCIPlay(play\Alias,play\FromPos,play\ToPos)
MessageRequester("Error","Error: "+MCIGetError(Error),#PB_MessageRequester_Ok)
MCIMsg = 0
Case #Register_Window
q.s = *p\FileName
Debug CallFunctionFast(*MCIWndCreate,WindowID(0),GetModuleHandle_(0),0,@q)
MCIMsg = 0
EndSelect
Until MCIMsg = #MCI_CLOSE
EndProcedure
Procedure WndProc(hwnd,umsg,wparam,lparam)
Result = #PB_ProcessPureBasicEvents
ProcedureReturn Result
EndProcedure
If OpenWindow(0,0,0,400,400,"",#PB_Window_ScreenCentered)
*p.MCIOpenParams = AllocateMemory(SizeOf(MCIOpenParams))
*p\Alias = "1"
*p\FileName = OpenFileRequester("Choose a File","","*.*",0)
SetWindowCallback(@WndProc())
CreateThread(@MCICallbackThread(),*p)
MCIMsg = #Register_Window
event.l
Repeat
Until event = #PB_Event_CloseWindow
EndIf