Toujours heureux de voir qu'il y a une bonne âme pour nous mettre sur la bonne voix.
Code : Tout sélectionner
;
;************************************************************************
;Titre : myVideoPlayer.pb
;Auteur : (C) 2024 CAGE
;Date : 2024/10/15
;Version PB : PureBasic 6.12 LTS (Windows - x86)
;Version PB : PureBasic 6.12 LTS (Windows - x64)
;Compiler Options
;Compiler Options : [x] Executable format: Windows
;Compiler Options : [x] Create threadsafe executable
;Compiler Options : [x] Enable moderm theme support (for Windows X and above)
;Compiler Options : [x] Enable DPI aware executable (Windows)
;Compiler Options : [x] Enable DLL preloading protection (Windows)
;Compile/Run : [x] Create temporary executable in the source directory
;
;Libairies: https://www.mediafire.com/file/jkqzr8sf8nxvkfr/pb.zip/file
;
;https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl
;************************************************************************
;
;Mes remerciement a CELTIC88 pour son post qui date du 3 Septembre 2021
;Voir https://www.purebasic.fr/english/viewtopic.php?t=77848
;
;Mes remerciement aussi pour:
;https://www.purebasic.fr/english/viewtopic.php?p=587630
;https://www.purebasic.fr/english/viewtopic.php?p=547029
;https://www.purebasic.fr/english/viewtopic.php?t=49471
;
;VLC x86/x64 a télécharger ici https://www.videolan.org/vlc/
;Il est possible d'installer les 2 versions
;
;Autres liens:
;https://wiki.videolan.org/LibVLC
;https://www.videolan.org/vlc/libvlc.html
;https://videolan.videolan.me/vlc/group__libvlc.html
;
;Mon post:
;https://www.purebasic.fr/french/viewtopic.php?t=19257
EnableExplicit
CompilerSelect #PB_Compiler_Thread
CompilerCase #False
CompilerError "L'option 'Activer la gestion des thread' doit etre activée."
CompilerDefault
CompilerEndSelect
CompilerSelect #PB_Compiler_EnableExplicit
CompilerCase #False
CompilerError "EnableExplicit doit etre indiqué."
CompilerDefault
CompilerEndSelect
CompilerSelect #PB_Compiler_ExecutableFormat
CompilerCase #PB_Compiler_Executable
CompilerDefault
CompilerError "L'option 'Format de l'exécutable:' doit être positionnée sur 'Windows'"
CompilerEndSelect
CompilerSelect #PB_Compiler_Processor
CompilerCase #PB_Processor_x86
#PROCESSOR="(x86)"
Define libvlc$="C:\Program Files (x86)\VideoLAN\VLC\libvlc.dll"
CompilerCase #PB_Processor_x64
#PROCESSOR="(x64)"
Define libvlc$="C:\Program Files\VideoLAN\VLC\libvlc.dll"
CompilerDefault
End
CompilerEndSelect
OnErrorGoto(?ErrorHandler)
Global AppPath$ = GetPathPart(ProgramFilename())
SetCurrentDirectory(AppPath$)
EnableDebugger
CompilerIf #PB_Compiler_Debugger
Procedure.a folderExist(f$)
If FileSize(f$) = -2
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Define f$
f$ = "x64"
If Not folderExist(f$)
If Not CreateDirectory(f$)
End
EndIf
EndIf
f$ = "x86"
If Not folderExist(f$)
If Not CreateDirectory(f$)
End
EndIf
EndIf
CompilerEndIf
CompilerIf #PB_Compiler_Debugger
;;; Nous sommes dans l'IDE
#WinApp = 123
CompilerElse
#WinApp = 99
CompilerEndIf
DisableDebugger
Enumeration Menus
#escp
#help
#hide
#kf10
#kf11
#mute
#pause
#play
#popup
#quit
#save
#scale
#show
#stop
#vers
#voldown
#volup
EndEnumeration
Enumeration Gadgets
#canvas
EndEnumeration
IncludeFile "lib\vlc.pb"
EnableExplicit
#WinAppTitle="myVideoPlayer v24.10.15 "+#PROCESSOR
Procedure.a appQuit()
Protected response, msgflags, message$
response = #PB_MessageRequester_Yes
msgflags = #PB_MessageRequester_YesNo|#PB_MessageRequester_Warning
message$ = "Voulez vous fermer l'application ?"
response = MessageRequester(#WinAppTitle,message$,msgflags)
If response = #PB_MessageRequester_Yes
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure.a GetAutoHideTaskBar()
;#Null ; 0 = #False
;#ABS_AUTOHIDE ; 1 = #True
Protected State.APPBARDATA
ProcedureReturn SHAppBarMessage_(#ABM_GETSTATE, State)
EndProcedure
Procedure.a SetAutoHideTaskBar(state)
;#Null ; 0 = #False
;#ABS_AUTOHIDE ; 1 = #True
Protected TaskBar, tbdata.AppBarData
TaskBar = FindWindow_("Shell_TrayWnd",0)
tbdata.AppBarData
tbdata\cbSize = SizeOf(tbdata)
tbdata\hwnd = TaskBar
tbdata\lParam = state
ProcedureReturn SHAppBarMessage_(#ABM_SETSTATE,@tbdata)
EndProcedure
Procedure.a fileExist(f$)
If FileSize(f$) < 0
ProcedureReturn #False
Else
ProcedureReturn #True
EndIf
EndProcedure
If fileExist(libvlc$)
vlc_loadlibvlc(libvlc$) ; select vlc dll
Else
MessageRequester(#WinAppTitle,"Vous devez installer VLC "+#PROCESSOR+" depuis www.videolan.org",#PB_MessageRequester_Ok|#PB_MessageRequester_Error)
End
EndIf
Define count = CountProgramParameters()
Global source$, titre$="Vidéo"
Select count
Case 1 : source$ = ProgramParameter(0)
Case 2 : source$ = ProgramParameter(0) : titre$ = GetFilePart(ProgramParameter(1))
Default : End
EndSelect
;Pour tester
CompilerIf #PB_Compiler_Debugger
;;; Nous sommes dans l'IDE
source$="https://dhx-caillou-2-eu.rakuten.wurl.tv/playlist.m3u8"
CompilerEndIf
source$=Trim(source$)
titre$ =Trim(titre$)
#bgcolor = #Black ; bgcolor = RGB(0,0,0)
#fgcolor = #White ; fgcolor = RGB(255,255,255)
#MINI=0
#MAXI=100
#HK_ALTV=$456 ; Alt + V
Define W=800, H=500
Define version$=vlc_version()
Define TB_INITIAL_STATE=GetAutoHideTaskBar()
If OpenWindow(#WinApp,0,0,W,H,"VLC "+version$+" "+#PROCESSOR+" :: "+titre$,#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget)
SetWindowColor(#WinApp,#bgcolor)
CanvasGadget(#canvas,0,0,W,H,#PB_Canvas_Container)
StartDrawing(CanvasOutput(#canvas))
;; on rempli le fond du canvas avec la couleur #bgcolor
FillArea(#canvas, 0, 0,#bgcolor)
StopDrawing()
CloseGadgetList()
If CreatePopupImageMenu(#popup)
MenuItem(#mute , "Couper/remettre le son" +Chr(9)+"M")
MenuItem(#pause, "Arrêter/reprendre la lecture"+Chr(9)+"Pause")
MenuBar()
MenuItem(#save , "Enregistrer la vidéo" +Chr(9)+"Ctrl+E")
MenuBar()
MenuItem(#help , "Affiche ce menu" +Chr(9)+"F1")
MenuItem(#kf10 , "Affiche la vidéo au format" +Chr(9)+"F10")
MenuItem(#kf11 , "Affiche la vidéo plein écran"+Chr(9)+"F11")
MenuBar()
MenuItem(#hide , "Réduire l'application" +Chr(9)+"Esc")
MenuItem(#show , "Réafficher l'application" +Chr(9)+"Alt+V")
MenuBar()
MenuItem(#quit , "Fermer le lecteur vidéo" +Chr(9)+"Q ou X")
MenuBar()
MenuItem(#escp , "Fermer ce menu")
EndIf
Define vlc
vlc = vlc_createplayer(GadgetID(#canvas),1)
vlc_setvolume(vlc,#MAXI)
vlc_play(vlc,source$)
AddKeyboardShortcut(#WinApp, #PB_Shortcut_Escape, #hide) ; réduire l'application dans la barre de tâche
AddKeyboardShortcut(#WinApp, #PB_Shortcut_Control+#PB_Shortcut_E, #save) ; enregistrer
AddKeyboardShortcut(#WinApp, #PB_Shortcut_F , #scale) ; scale
AddKeyboardShortcut(#WinApp, #PB_Shortcut_M , #mute) ; mute
AddKeyboardShortcut(#WinApp, #PB_Shortcut_Q , #quit) ; quit
AddKeyboardShortcut(#WinApp, #PB_Shortcut_X , #quit) ; quit
AddKeyboardShortcut(#WinApp, #PB_Shortcut_V , #vers) ; version
;
AddKeyboardShortcut(#WinApp, #PB_Shortcut_Pause, #pause) ; met en pause la vidéo
AddKeyboardShortcut(#WinApp, #PB_Shortcut_Home , #play) ; relance la vidéo
AddKeyboardShortcut(#WinApp, #PB_Shortcut_End , #stop) ; arrête la vidéo
;
;Touches dédiées au réglage du volume
AddKeyboardShortcut(#WinApp, #VK_VOLUME_DOWN , #voldown) ; diminue le volume
AddKeyboardShortcut(#WinApp, #VK_VOLUME_UP , #volup) ; augmente le volume
AddKeyboardShortcut(#WinApp, #VK_VOLUME_MUTE , #mute) ; augmente le volume
;
;Touches génériques pour le réglage du volume
AddKeyboardShortcut(#WinApp, #PB_Shortcut_Left , #voldown) ; diminue le volume
AddKeyboardShortcut(#WinApp, #PB_Shortcut_Right, #volup) ; augmente le volume
;
;Touches génériques pour le réglage du volume
AddKeyboardShortcut(#WinApp, #PB_Shortcut_Up , #volup) ; augmente le volume
AddKeyboardShortcut(#WinApp, #PB_Shortcut_Down , #voldown) ; diminue le volume
;
AddKeyboardShortcut(#WinApp, #PB_Shortcut_F1 , #help) ; Affiche le popup
AddKeyboardShortcut(#WinApp, #PB_Shortcut_F10 , #kf10) ; Affiche la vidéo au format
AddKeyboardShortcut(#WinApp, #PB_Shortcut_F11 , #kf11) ; Affiche la fenêtre en plein écran
Define hWnd,RetVal
hWnd=WindowID(#WinApp)
RetVal = SendMessage_(hWnd, #WM_SETHOTKEY, #HK_ALTV, 0) ; Alt + V $456
If RetVal
DefWindowProc_(hWnd,#WM_SHOWWINDOW, 0, 0)
EndIf
Define Event,indexGadget,valeur,indexGadgetType,indexMenu
Define volume=#MAXI,scale=#False,fullscr=#False
Repeat
Event = WaitWindowEvent(50)
Select Event
;====================
;=== EVENTS MENUS ===
;====================
Case #WM_LBUTTONDOWN
;
Case #WM_RBUTTONDOWN
DisplayPopupMenu(#popup,WindowID(#WinApp),GadgetX(#canvas,#PB_Gadget_ScreenCoordinate),GadgetY(#canvas,#PB_Gadget_ScreenCoordinate))
Case #PB_Event_Menu
indexMenu = EventMenu()
Select indexMenu
Case #help
DisplayPopupMenu(#popup,WindowID(#WinApp),GadgetX(#canvas,#PB_Gadget_ScreenCoordinate),GadgetY(#canvas,#PB_Gadget_ScreenCoordinate))
Case #hide
SetWindowState(#WinApp, #PB_Window_Minimize)
Case #show
SetWindowState(#WinApp, #PB_Window_Normal)
Case #mute
;vlc_setvolume(vlc,#MINI)
vlc_onoffsound(vlc)
Case #pause
vlc_pauseplay(vlc)
Case #play
vlc_play(vlc,source$)
Case #save
RunProgram("myVideoDownloader.exe",Chr(34)+source$+Chr(34)+" "+Chr(34)+titre$+Chr(34),#Empty$)
Case #kf11
fullscr=Bool(fullscr=0)
If fullscr
fullscr=#True
If GetAutoHideTaskBar()=#False
SetAutoHideTaskBar(#True)
EndIf
;vlc_setvideoscale(vlc,fullscr)
SetWindowState(#WinApp, #PB_Window_Maximize)
SetWindowLong_(hWnd, #GWL_STYLE, GetWindowLong_(hWnd, #GWL_STYLE)&~#WS_CAPTION&~#WS_SIZEBOX)
ResizeGadget(#canvas,0,0,WindowWidth(#WinApp,#PB_Window_FrameCoordinate),WindowHeight(#WinApp,#PB_Window_FrameCoordinate))
Else
fullscr=#False
SetAutoHideTaskBar(TB_INITIAL_STATE)
vlc_setvideoscale(vlc,fullscr)
ShowWindow_(WindowID(#WinApp), #SW_SHOWNORMAL)
SetWindowLong_(hWnd, #GWL_STYLE, GetWindowLong_(hWnd, #GWL_STYLE)|#WS_CAPTION|#WS_SIZEBOX)
EndIf
Case #scale
; Met la fenêtre en plein écran
SetWindowState(#WinApp, #PB_Window_Maximize)
scale=Bool(scale=0)
vlc_setvideoscale(vlc,scale)
Case #stop
vlc_stopplayer(vlc)
Case #vers
MessageRequester(#WinAppTitle,"VLC version "+vlc_version())
Case #kf10
Define vw=vlc_getvideowidth(vlc)
Define vh=vlc_getvideoheight(vlc)
If vw>100 And vh>100
ResizeWindow(#WinApp,#PB_Ignore,#PB_Ignore,vw,vh)
EndIf
Case #voldown
RunProgram("sndvol.exe","-f " + Str(65536*DesktopMouseY() + DesktopMouseX()),"")
If volume > 0
volume-1
vlc_setvolume(vlc,volume)
EndIf
Case #volup
RunProgram("sndvol.exe","-f " + Str(65536*DesktopMouseY() + DesktopMouseX()),"")
If volume < 100
volume+1
vlc_setvolume(vlc,volume)
EndIf
Case #quit
If appQuit() : Break : EndIf
EndSelect
;=====================
;=== EVENTS GADGET ===
;=====================
;Case #PB_Event_Gadget
; indexGadget = EventGadget()
; indexGadgetType = EventType()
; Select indexGadget
; Case #canvas
; Select indexGadgetType
; Case #PB_Event_LeftClick
; DisplayPopupMenu(#popup,WindowID(#WinApp))
; EndSelect
; EndSelect
;=======================
;=== EVENTS SYSTEMES ===
;=======================
Case #PB_Event_MaximizeWindow
;vlc_setvideoscale(vlc,#True)
Case #PB_Event_SizeWindow
Debug "size windows"
scale=#False
vlc_setvideoscale(vlc,scale)
ResizeGadget(#canvas,#PB_Ignore,#PB_Ignore,WindowWidth(#winapp,#PB_Window_FrameCoordinate),WindowHeight(#WinApp,#PB_Window_FrameCoordinate))
Case #PB_Event_CloseWindow
SetWindowState(#WinApp, #PB_Window_Minimize)
EndSelect
ForEver
EndIf
vlc_freeplayer(vlc)
SetAutoHideTaskBar(TB_INITIAL_STATE)
ErrorHandler:
End
Vous trouverez dans le code les autres touches utilisées.
Ce code n'est pas forcément finalisé, aussi tout retour (améliorations, critiques, suggestions,...) sera apprécié.