
Hello forum! I'm a newbie.


Perhaps I should ask the Mplayer-team for advice but i fear that they don't understand PB so here we go. My example is controlling the Mplayer in slavemode. I want to show the video on the Purebasic window, perhaps on an imagegadget or canvasgadget.
In my next posting is a longer testprog with ten different ID-options where none is working. You may prefer the first posting for starters.
Questions:
1) What kind of ID is needed in the mplayer command -wid aka WindowID.
Thanks in advance// Sigge
Code: Select all
EnableExplicit
Define.s sMplayerPath,sMp3Path,sDVDpath,sAVIpath,sMpegPath,sAppPath,sFile,sOutput
Define lEvent,FlagLatestButton,hndMplayer,hndImage_MEDIA,hndVideoWindow,lResult,ElapsedTime,StartTime,ctr
#DVD_Browser=1
#WinW = 777
#MarginR = 22
Enumeration;Windows
#Window
#VideoWindow
EndEnumeration
Enumeration ; Gadgets
#sgdMplayerPath
#btnBrowseMplayerPath
#sgdMp3Path
#btnBrowseMp3Path
#sgdDVDpath
#btnDVDPath
#sgdAVIpath
#btnAVIPath
#sgdMpegpath
#btnMpegPath
#btnPlayMp3
#btnPlayDVD
#btnPlayAVI
#btnPlayMpeg
#btnPlay
#btnPause
#btnStop
#btnCloseMplayer
#chbFlushing
#StringGadgetFlush
#EditorGadget
#imgGdtMovie
EndEnumeration
Enumeration;Images
#imgMovie_MEDIA
EndEnumeration
Procedure.l HandleError(Result.l, WarningText.s, lResume=#False)
If Result = 0
MessageRequester("Error", WarningText, #PB_MessageRequester_Ok)
If lResume=#False
End;Stop programme!
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Procedure.l GetLatestPaths(sAppPath.s);sMplayerPath.s,sMp3Path.s,sDVDpath.s,sAVIpath.s,sMpegPath.s,sAppPath.s)
Define lResult
Shared sMplayerPath,sMp3Path,sDVDpath,sAVIpath,sMpegPath
;Opens too read from the ini-file of the form.
lResult = OpenPreferences(sAppPath+"MplayerTest.ini")
If lResult
PreferenceGroup("Latest_Paths")
sMplayerPath = ReadPreferenceString("sMplayerPath", "")
sMp3Path = ReadPreferenceString("sMp3Path", "")
sDVDpath = ReadPreferenceString("sDVDpath", "")
sAVIpath = ReadPreferenceString("sAVIpath", "")
sMpegPath = ReadPreferenceString("sMpegPath", "")
SetGadgetText(#sgdMplayerPath,sMplayerPath)
SetGadgetText(#sgdMp3Path,sMp3Path)
SetGadgetText(#sgdDVDpath,sDVDpath)
SetGadgetText(#sgdAVIpath,sAVIpath)
SetGadgetText(#sgdMpegpath,sMpegPath)
ClosePreferences()
EndIf;OpenPreferences
ProcedureReturn lResult
EndProcedure
Procedure.l SetLatestPaths(sMplayerPath.s,sMp3Path.s,sDVDpath.s,sAVIpath.s,sMpegPath.s,sAppPath.s)
Define lResult.l
;Opens to read from the ini-file of the form.
lResult = OpenPreferences(sAppPath+"MplayerTest.ini")
If lResult
PreferenceGroup("Latest_Paths")
WritePreferenceString("sMplayerPath",sMplayerPath)
WritePreferenceString("sMp3Path",sMp3Path)
WritePreferenceString("sDVDpath",sDVDpath)
WritePreferenceString("sAVIpath",sAVIpath)
WritePreferenceString("sMpegPath",sMpegPath)
ClosePreferences()
Else
MessageRequester("Err","OpenPreferences(sAppPath + MplayerTest.ini)")
EndIf;lResult OpenPreferences
ProcedureReturn lResult
EndProcedure
Procedure.s Browse(sStandardFile.s,sPattern.s)
Define Pattern.l, sFile.s
;sStandardFile is mostly = sAppPath ; set initial file+path to display
; With next string we will set the search patterns ("|" as separator) for file displaying:
; 1st: "Text (*.txt)" as name, ".txt" and ".bat" as allowed extension
; 2nd: "PureBasic (*.pb)" as name, ".pb" as allowed extension
; 3rd: "All files (*.*) as name, "*.*" as allowed extension, valid for all files
;sPattern = "Text (*.txt)|*.txt;*.bat|PureBasic (*.pb)|*.pb|All files (*.*)|*.*"
If sPattern <>Str(#DVD_Browser)
Pattern = 0 ; use the first of the three possible patterns as standard
sFile = OpenFileRequester("Please select file!", sStandardFile, sPattern, Pattern)
Else;#DVD_Browser
sFile = PathRequester("Please select DVD-Unit!",sStandardFile)
EndIf
If sFile = ""
MessageRequester("Information", "The requester was canceled.", 0)
EndIf
ProcedureReturn sFile
EndProcedure
Procedure AssignPathToString(sFile.s,lStrGadget.l,sMplayerPath.s,sMp3Path.s,sDVDpath.s,sAVIpath.s,sMpegPath.s,sAppPath.s)
If sFile
SetGadgetText(lStrGadget,sFile)
EndIf
SetLatestPaths(sMplayerPath,sMp3Path,sDVDpath,sAVIpath,sMpegPath,sAppPath)
EndProcedure
Procedure.s ShortPath(sFile.s)
;DOS-format for For mplayer and FFmeg etc
Define sBuffer.s, ResultLength.l, s.s
sBuffer = Space(255)
ResultLength = GetShortPathName_(sFile, @sBuffer, 255)
s = Left(sBuffer, ResultLength)
ProcedureReturn s
EndProcedure
Procedure LoungeMplayer(sFile.s,sMplayerPath.s)
Shared hndMplayer,hndImage_MEDIA,hndVideoWindow
If sMplayerPath
If sFile
If Right(sFile,1)="\";Not a file but a folder, probably the DVD root.
;RunProgram("H:\Programvara\VideoProgram\Mplayer 2007\GUI\MPUI\mplayer.exe", "-slave -identify -wid " + Str(hndImage_MEDIA) + " -colorkey 0x101010 -nokeepaspect -framedrop -autosync 100 -vf screenshot -font C:\WINDOWS\Fonts\Arial.ttf -priority abovenormal -ao dsound:device=0 -autoq 10 -vf-add pp -dvd-device E:\ dvd://","");
RunProgram(sMplayerPath, "-slave -identify -wid " + Str(hndImage_MEDIA) + " -colorkey 0x101010 -nokeepaspect -framedrop -autosync 100 -vf screenshot -font C:\WINDOWS\Fonts\Arial.ttf -priority abovenormal -ao dsound:device=0 -autoq 10 -vf-add pp -dvd-device E:\ dvd://","")
;RunProgram(sMplayerPath, "-slave -identify -wid " + Str(hndVideoWindow) + " -colorkey 0x101010 -nokeepaspect -framedrop -autosync 100 -vf screenshot -font C:\WINDOWS\Fonts\Arial.ttf -priority abovenormal -ao dsound:device=0 -autoq 10 -vf-add pp -dvd-device E:\ dvd://","")
;RunProgram(sMplayerPath, "-slave -quiet -dvd-device " + ShortPath(sFile) + " dvd:\\","")
Else
;RunProgram(sMplayerPath, ShortPath(sFile),"")
hndMplayer = RunProgram(sMplayerPath, " -slave " + ShortPath(sFile),"",#PB_Program_Open|#PB_Program_Read|#PB_Program_Write)
EndIf;Right(sFile,1)
EndIf;sFile
Else
MessageRequester("Err","Please locate the sMplayerPath!")
EndIf;sMplayerPath
EndProcedure
Procedure CleanUpMplayer(hndMplayer.l)
StopDrawing()
If IsProgram(hndMplayer)
KillProgram(hndMplayer);Terminator
CloseProgram(hndMplayer);Closes the connection.
EndIf
EndProcedure
;hndVideoWindow = OpenWindow(#VideoWindow, 0, 0, 777, 555, "VideoWindow", #PB_Window_SystemMenu)
;hndVideoWindow =StartDrawing(WindowOutput(#VideoWindow))
If OpenWindow(#Window, 0, 0, 777, 555, "MplayerTest", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CompilerIf #PB_Compiler_Debugger
sAppPath = GetCurrentDirectory()
CompilerElse
sAppPath = GetPathPart(ProgramFilename())
CompilerEndIf
StringGadget(#sgdMplayerPath,10,10,555,18,sMplayerPath)
ButtonGadget(#btnBrowseMplayerPath,566,10,200,18,"BrowseMplayerPath")
StringGadget(#sgdMp3Path,10,30,555,18,sMp3Path)
ButtonGadget(#btnBrowseMp3Path,566,30,200,18,"BrowseMp3Path")
StringGadget(#sgdDVDpath,10,50,555,18,sDVDpath)
ButtonGadget(#btnDVDPath,566,50,200,18,"BrowseDVD_Path")
StringGadget(#sgdAVIpath,10,70,555,18,sAVIpath)
ButtonGadget(#btnAVIPath,566,70,200,18,"BrowseAVI_Path")
StringGadget(#sgdMpegpath,10,90,555,18,sMpegPath)
ButtonGadget(#btnMpegPath,566,90,200,18,"BrowseMpegPath")
ButtonGadget(#btnPlayMp3,10,122,200,33,"PlayMp3")
ButtonGadget(#btnPlayDVD,10,172,200,33,"PlayDVD")
ButtonGadget(#btnPlayAVI,10,222,200,33,"PlayAVI")
ButtonGadget(#btnPlayMpeg,10,272,200,33,"PlayMpeg")
ButtonGadget(#btnPlay,10,322,66,33,"Play")
ButtonGadget(#btnPause,66,322,66,33,"Pause")
ButtonGadget(#btnStop,132,322,66,33,"Stop")
ButtonGadget(#btnCloseMplayer,10,372,200,33,"Close Mplayer")
CheckBoxGadget(#chbFlushing,240,122,99,22,"Allow flushing!")
SetGadgetState(#chbFlushing,#PB_Checkbox_Checked)
GadgetToolTip(#chbFlushing,"Same result as moving mouse!?")
StringGadget(#StringGadgetFlush,350,122,#WinW-350-#MarginR,22,"Why need flushing ReadprogramString OR move mouse!?")
EditorGadget(#EditorGadget,240,152,#WinW-240-#MarginR,133)
CreateImage(#imgMovie_MEDIA,296,222)
;=============================================
hndImage_MEDIA = ImageID(#imgMovie_MEDIA); = NECESSARY AND I DONT KNOW WHY!:-<
;=============================================
hndImage_MEDIA=StartDrawing(ImageOutput(#imgMovie_MEDIA))
ImageGadget(#imgGdtMovie,240,312, 296,222,ImageID(#imgMovie_MEDIA),#PB_Image_Border)
If FileSize(sAppPath+"MplayerTest.ini") <> -1
GetLatestPaths(sAppPath);sMplayerPath,sMp3Path,sDVDpath,sAVIpath,sMpegPath,sAppPath)
Else
CreatePreferences(sAppPath+"MplayerTest.ini")
EndIf
Repeat
lEvent=WaitWindowEvent(500)
Select EventGadget()
;BROWSER_BUTTONS
Case #btnBrowseMplayerPath
sFile = Browse(sAppPath,"mplayer.exe|mplayer.exe|All files (*.*)|*.*")
If sFile: sMplayerPath=sFile: AssignPathToString(sFile,#sgdMplayerPath,sMplayerPath,sMp3Path,sDVDpath,sAVIpath,sMpegPath,sAppPath):EndIf
Case #btnBrowseMp3Path
sFile = Browse(sAppPath,"AudioFile (*.mp3)|*.mp3|All files (*.*)|*.*")
If sFile: sMp3Path=sFile: AssignPathToString(sFile,#sgdMp3Path,sMplayerPath,sMp3Path,sDVDpath,sAVIpath,sMpegPath,sAppPath):EndIf
Case #btnDVDPath
sFile = Browse("C:\",Str(#DVD_Browser))
If sFile: sDVDpath=sFile: AssignPathToString(sFile,#sgdDVDpath,sMplayerPath,sMp3Path,sDVDpath,sAVIpath,sMpegPath,sAppPath):EndIf
Case #btnAVIPath
sFile = Browse(sAppPath,"VideoFile (*.avi)|*.avi|All files (*.*)|*.*")
If sFile: sAVIpath=sFile: AssignPathToString(sFile,#sgdAVIpath,sMplayerPath,sMp3Path,sDVDpath,sAVIpath,sMpegPath,sAppPath):EndIf
Case #btnMpegPath
sFile = Browse(sAppPath,"VideoFile (*.mpg)|*.mpg|All files (*.*)|*.*")
If sFile: sMpegPath=sFile: AssignPathToString(sFile,#sgdMpegpath,sMplayerPath,sMp3Path,sDVDpath,sAVIpath,sMpegPath,sAppPath):EndIf
;PLAY_BUTTONS
Case #btnPlayMp3
If FlagLatestButton<>#btnPlayMp3
LoungeMplayer(sMp3Path,sMplayerPath)
FlagLatestButton=#btnPlayMp3
EndIf
Case #btnPlayAVI
If FlagLatestButton<>#btnPlayAVI
LoungeMplayer(sAVIpath,sMplayerPath)
FlagLatestButton=#btnPlayAVI
EndIf
Case #btnPlayDVD
If FlagLatestButton<>#btnPlayDVD
LoungeMplayer(sDVDpath,sMplayerPath)
FlagLatestButton=#btnPlayDVD
EndIf
Case #btnPlayMpeg
If FlagLatestButton<>#btnPlayMpeg
LoungeMplayer(sMpegPath,sMplayerPath)
FlagLatestButton=#btnPlayMpeg
EndIf
Case #btnPlay
If FlagLatestButton<>#btnPlay
If IsProgram(hndMplayer)
lResult=WriteProgramStringN(hndMplayer, "play")
Debug Str(lResult) + " play"
EndIf
FlagLatestButton=#btnPlay
EndIf;FlagLatestButton<>#btnPlay
Case #btnPause
If FlagLatestButton<>#btnPause
If IsProgram(hndMplayer)
lResult=WriteProgramStringN(hndMplayer, "pause")
Debug Str(lResult) + " pause"
EndIf
FlagLatestButton=#btnPause
EndIf;FlagLatestButton<>#btnPause
Case #btnStop
If FlagLatestButton<>#btnStop
If IsProgram(hndMplayer)
lResult=WriteProgramStringN(hndMplayer, "stop")
Debug Str(lResult) + " stop"
EndIf
FlagLatestButton=#btnStop
EndIf;FlagLatestButton<>#btnStop
Case #btnCloseMplayer
CleanUpMplayer(hndMplayer)
EndSelect
If IsProgram(hndMplayer)
If ProgramRunning(hndMplayer)
If AvailableProgramOutput(hndMplayer)
sOutput = ReadProgramString(hndMplayer) + Chr(13)
If Left(sOutput,2) = "A:";Filtering the recurring msgs.
If GetGadgetState(#chbFlushing)
SetGadgetText(#StringGadgetFlush, sOutput)
EndIf
Else
AddGadgetItem(#EditorGadget, 0, sOutput)
EndIf
EndIf;AvailableProgramOutput(hndMplayer)
Else;Not programRunning(hndMplayer)
CloseProgram(hndMplayer);Closes the connection.
EndIf;ProgramRunning
EndIf;IsProgram(hndMplayer)
Until lEvent = #PB_Event_CloseWindow
EndIf; OpenWindow
CleanUpMplayer(hndMplayer)
End