J'aurai voulu ajouter la fonction HotKey {p} pour envoyer la fonction pause à mplayer et {f} pour le plein écran mais sans succès.
J'en suis à ce bout de code et pourtant j'ai bien le même pid et la fonction n'est pas envoyée

Auriez-vous une idée ?
Merci d'avance...
► Afficher le texte
Code : Tout sélectionner
#include <Constants.au3>
#include <File.au3>
#include <GuiButton.au3>
#include <GuiConstantsEx.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <SliderConstants.au3>
#include <String.au3>
#NoTrayIcon
;FileInstall("mplayer.exe","mplayer.exe") ; Embedded mplayer.exe FileInstall("Wii.jpg",@TempDir&"\Wii.jpg")
Local $mplayerpid, $StdoutRead, $Pause, $Seek_To
HotKeySet("{p}", "HotKeyPressed") ; <=== la touche p pour pause
HotKeySet("{f}", "HotKeyPressed") ; <=== la touche f pour plein écran
Func HotKeyPressed()
Switch @HotKeyPressed ; Le dernier raccourci utilisé.
Case "{p}"
If ProcessExists($mplayerpid) Then ; et que mplayer est lancé
StdinWrite($mplayerpid, "pause" & @LF) ; envoie la 'Pause' à MPlayer
ConsoleWrite("En Pause ? " & $mplayerpid & @LF)
Else
ConsoleWrite("En Lecture ? " & $mplayerpid & @LF)
EndIf
Case "{f}"
If ProcessExists($mplayerpid) Then ; et que mplayer est lancé
StdinWrite($mplayerpid, @LF & 'vo_fullscreen' & @LF) ; envoie le 'Plein écran' à MPlayer
ConsoleWrite("En Plein écran ? " & $mplayerpid & @LF)
Else
ConsoleWrite("En mode fenêtre ? " & $mplayerpid & @LF)
EndIf
EndSwitch
EndFunc
$s_mplayer_location = 'mplayer.exe'
$s_media_location = 'video.mp4'
;$s_media_location = 'Preview.avs'
$h_GUI_Main = GUICreate("Embedded MPlayer Test - MT (Multi Threading)", 640, 480, -1, -1, $WS_CLIPCHILDREN + $WS_OVERLAPPEDWINDOW)
$a_Pos_GUI_Main = WinGetPos($h_GUI_Main)
$Font = "Times New Roman"
GUISetFont(8, 400, 1, $Font)
$Label_Time_Now = GUICtrlCreateLabel(" --:--:-- ", 4, 429)
GUICtrlSetResizing($Label_Time_Now, $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKSIZE)
$Slider_Bar_Progress = GUICtrlCreateSlider(40, 428, 558, 23, BitOR($TBS_ENABLESELRANGE,$TBS_BOTH + $TBS_NOTICKS + $TBS_REVERSED))
GUICtrlSetResizing($Slider_Bar_Progress, $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKSIZE)
$Time_Length = GUICtrlCreateLabel(" --:--:-- ", 598, 429)
GUICtrlSetResizing($Time_Length, $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT + $GUI_DOCKSIZE)
$c_button_play = GUICtrlCreateButton("Play",3,446,32,32)
GUICtrlSetResizing($c_button_play, $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKSIZE)
$c_button_stop = GUICtrlCreateButton("Stop",48,449,26,26)
GUICtrlSetResizing($c_button_stop, $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKSIZE)
$c_button_mute = GUICtrlCreateButton("Mute",75,449,26,26)
GUICtrlSetResizing($c_button_mute, $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKSIZE)
$Label_Infos = GUICtrlCreateLabel("MPlayer", 250, 450, 470, 46)
GUICtrlSetResizing($Label_Infos, $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKSIZE)
;$a_Pos_GUI_Main = WinGetPos($h_GUI_Main)
$h_GUI_Slave = GUICreate("Embedded MPlayer Test - Slave Window", $a_Pos_GUI_Main[2] - 100, $a_Pos_GUI_Main[3] - 100, $a_Pos_GUI_Main[0] + 50, $a_Pos_GUI_Main[1] + 50, $WS_POPUP, $HWND_TOP)
GuiSetBkColor(0x000000, $h_GUI_Slave)
_embed_GUI($h_GUI_Main, $h_GUI_Slave, 0, 0, $a_Pos_GUI_Main[2], $a_Pos_GUI_Main[3] - 150)
GUISetState(@SW_SHOW, $h_GUI_Slave)
GUISetState(@SW_SHOW, $h_GUI_Main)
GUIRegisterMsg($WM_SIZING, "WM_SIZING")
#forceref $hWnd, $iMsg, $wParam, $lParam
WM_SIZING()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $GUI_EVENT_MAXIMIZE
WM_SIZING()
Case $msg = $GUI_EVENT_RESTORE
WM_SIZING()
Case $msg = $GUI_EVENT_PRIMARYDOWN
MPlayer_Seek()
Case $msg = $c_button_play
Select
Case GUICtrlRead($c_button_play) = 'Play' ; Si j'appuie sur 'Play'
If ProcessExists($mplayerpid) Then ; et que mplayer est lancé
GUICtrlSetData($c_button_play,'Pause') ; change le bouton 'Play' en 'Pause'
StdinWrite($mplayerpid, "pause" & @LF) ; envoie la 'Pause' à MPlayer
Else ; Si MPlayer n'est pas lancé
Run_MPlayer() ; lance MPlayer
GUICtrlSetData($c_button_play,'Pause') ; change le bouton 'Play' en 'Pause'
EndIf
Case Else ; Si j'appuie sur 'Pause'
StdinWrite($mplayerpid, "pause" & @LF) ; envoie la 'Pause' à MPlayer
GUICtrlSetData($c_button_play,'Play') ; change le bouton 'Pause' en 'Play'
EndSelect
Case $msg = $c_button_stop
Select
Case GUICtrlRead($c_button_stop) = 'Stop'
MPlayer_Stop()
EndSelect
;StdinWrite($mplayerpid, "pause" & @LF)
Case $msg = $c_button_mute
Select
Case GUICtrlRead($c_button_mute) = 'Mute'
GUICtrlSetData($c_button_mute,'Unmute')
Case Else
GUICtrlSetData($c_button_mute,'Mute')
EndSelect
StdinWrite($mplayerpid, "mute" & @LF)
EndSelect
Sleep(10)
If GUICtrlRead($c_button_play) = 'Pause' Then MPlayer_Stdout_Read()
WEnd
ProcessClose($mplayerpid)
Exit
Func Run_MPlayer()
;Local $TimeLen ; -colorkey 000000
;$MPlayer_Screen = Number($h_GUI_Main)
$MPlayer_Screen = Number($h_GUI_Slave)
$mplayerOpt = ' -nofontconfig'
$mplayerOpt &= ' -slave'
$mplayerOpt &= ' -lavdopts threads=24'
;~ $mplayerOpt &= ' -v'
$mplayerOpt &= ' -vo direct3d'
$mplayerOpt &= ' -colorkey 000000'
$mplayerOpt &= ' -fps 10'
$mplayerpid = Run('"' & $s_mplayer_location & '"'&$s_media_location&'"' & '" -wid ' & $MPlayer_Screen & $mplayerOpt, '', @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
;$mplayerpid = Run('"' & $s_mplayer_location & '" -nofontconfig -noborder -lavdopts threads=12 -wid ' & $MPlayer_Screen & ' -v -vo direct3d -colorkey 000000 "' & $s_media_location & '"', '')
;~ Sleep(2000)
;~ HotKeySet("{f}", StdinWrite($mplayerpid, @LF & 'vo_fullscreen' & @LF))
;~ HotKeySet("{p}", StdinWrite($mplayerpid, "pause" & @LF))
StdinWrite($mplayerpid, "pause" & @LF) ; envoie la 'Pause' à MPlayer
ConsoleWrite("$mplayerpid = " & $mplayerpid & @LF)
EndFunc
Func MPlayer_Stdout_Read()
If ProcessExists($mplayerpid) Then
Else
MPlayer_Stop()
EndIf
$StdoutRead = StdoutRead($mplayerpid)
If StringInStr($StdoutRead, "===== PAUSE =====") Then
Else
;If GUICtrlRead($c_button_play) = 'Pause' Then
;~ StdinWrite($mplayerpid, @LF & "get_time_pos" & @LF & _ ; ANS_TIME_POSITION=0.0
;~ "get_time_length" & @LF & _ ; ANS_LENGTH=229.15
;~ "get_vo_fullscreen" & @LF) ; ANS_VO_FULLSCREEN=0
StdinWrite($mplayerpid, @LF & "get_time_pos" & @LF & _ ; ANS_TIME_POSITION=0.0
"get_time_length" & @LF & _ ; ANS_LENGTH=229.15
"get_property width" & @LF & _ ; ANS_width=720
"get_property height" & @LF & _ ; ANS_height=480
"get_meta_title" & @LF & _ ; ANS_META_TITLE=''
"get_file_name" & @LF & _ ; ANS_FILENAME='test1.mkv'
"get_meta_album" & @LF & _ ; ANS_META_ALBUM=''
"get_meta_artist" & @LF & _ ; ANS_META_ARTIST=''
"get_meta_comment" & @LF & _ ; ANS_META_COMMENT=''
"get_meta_genre" & @LF & _ ; ANS_META_GENRE=''
"get_meta_track" & @LF & _ ; ANS_META_TRACK=''
"get_meta_year" & @LF & _ ; ANS_META_YEAR=''
"get_video_resolution" & @LF & _ ; ANS_VIDEO_RESOLUTION='720 x 480'
"get_video_codec" & @LF & _ ; ANS_VIDEO_CODEC='H264'
"get_audio_bitrate" & @LF & _ ; ANS_AUDIO_BITRATE=''
"get_audio_codec" & @LF & _ ; ANS_AUDIO_CODEC=''
"get_video_bitrate" & @LF & _ ; ANS_VIDEO_BITRATE='0 kbps'
"get_vo_fullscreen" & @LF) ; ANS_VO_FULLSCREEN=0
$StdoutRead = StdoutRead($mplayerpid)
EndIf
If StringInStr($StdoutRead, "ANS_TIME_POSITION") > 0 Then
$ANS_TIME_POSITION = _StringBetween($StdoutRead, "ANS_TIME_POSITION=", @LF)
$ANS_TIME_POSITION = Int(StringStripWS($ANS_TIME_POSITION[0], 7))
GUICtrlSetData($Slider_Bar_Progress, $ANS_TIME_POSITION) ; Met à jour la barre de progression
$sec2time_hour = Int($ANS_TIME_POSITION / 3600)
$sec2time_min = Int(($ANS_TIME_POSITION - $sec2time_hour * 3600) / 60)
$sec2time_sec = $ANS_TIME_POSITION - $sec2time_hour * 3600 - $sec2time_min * 60
$ANS_TIME_POSITION = StringFormat('%02d:%02d:%02d', $sec2time_hour, $sec2time_min, $sec2time_sec)
GUICtrlSetData($Label_Time_Now, $ANS_TIME_POSITION) ; Durée en cours 00:00:12
EndIf
If StringInStr($StdoutRead, "ANS_LENGTH") > 0 Then
$ANS_LENGTH = _StringBetween($StdoutRead, "ANS_LENGTH=", @LF)
$ANS_LENGTH = Int(StringStripWS($ANS_LENGTH[0], 7))
GUICtrlSetLimit($Slider_Bar_Progress, $ANS_LENGTH, 0) ; change min/max value de la barre de progression en secondes
$sec2time_hour = Int($ANS_LENGTH / 3600)
$sec2time_min = Int(($ANS_LENGTH - $sec2time_hour * 3600) / 60)
$sec2time_sec = $ANS_LENGTH - $sec2time_hour * 3600 - $sec2time_min * 60
$ANS_LENGTH = StringFormat('%02d:%02d:%02d', $sec2time_hour, $sec2time_min, $sec2time_sec)
GUICtrlSetData($Time_Length, $ANS_LENGTH) ; Durée totale 02:31:49
EndIf
If StringInStr($StdoutRead, "ANS_VO_FULLSCREEN") Then
$ANS_VO_FULLSCREEN = _StringBetween($StdoutRead, "ANS_VO_FULLSCREEN=", @LF)
$ANS_VO_FULLSCREEN = StringStripWS($ANS_VO_FULLSCREEN[0], 7)
EndIf
;_FileWriteLog(@ScriptDir & "\MPlayer.log", $StdoutRead)
;GUICtrlSetData($Label_Infos, $StdoutRead)
EndFunc
Func MPlayer_Seek()
$GUIGetCursorInfo = GUIGetCursorInfo()
If $GUIGetCursorInfo[4] = $Slider_Bar_Progress Then
While _IsPressed("01")
$Seek_To = GUICtrlRead($Slider_Bar_Progress)
WEnd
;ConsoleWrite("$Seek_To="&$Seek_To & @CRLF) ;show at release otherwise it becomes a mess
StdinWrite($mplayerpid,"seek "& $Seek_To &" 2" & @LF)
;GUICtrlSetData($Slider_Bar_Progress, $ANS_TIME_POSITION) ; Met à jour la barre de progression
EndIf
EndFunc
Func MPlayer_Stop()
StdinWrite($mplayerpid, "stop" & @LF)
GUICtrlSetData($c_button_play,'Play') ; change le bouton 'Pause' en 'Play'
GUICtrlSetData($Label_Time_Now, "00:00:00") ; Durée en cours 00:00:12
GUICtrlSetData($Time_Length, "00:00:00") ; Durée totale 02:31:49
GUICtrlSetData($Slider_Bar_Progress, "0") ; Met à jour la barre de progression
GUICtrlSetData($c_button_mute,'Unmute')
EndFunc
Func _embed_GUI($h_Wnd_outer, $h_Wnd_inner, $x, $y, $w = "", $h = "")
$nExStyle = DllCall("user32.dll", "int", "GetWindowLong", "hwnd", $h_Wnd_inner, "int", -20)
$nExStyle = $nExStyle[0]
DllCall("user32.dll", "int", "SetWindowLong", "hwnd", $h_Wnd_inner, "int", -20, "int", BitOR($nExStyle, $WS_EX_MDICHILD))
DllCall("user32.dll", "int", "SetParent", "hwnd", $h_Wnd_inner, "hwnd", $h_Wnd_outer)
WinMove($h_Wnd_inner, "", $x, $y, $w, $h)
EndFunc ;==>_embed_GUI
Func WM_SIZING()
$SRC = -8
$ParentSize = WinGetClientSize($h_GUI_Main)
WinMove($h_GUI_Slave, "", $SRC, $SRC, $ParentSize[0]-$SRC*2, $ParentSize[1]-$SRC*2-60)
EndFunc ;==>WM_SIZING