[ok] Lecteur OGG bouffeur de ressources
Publié : mer. 09/sept./2015 13:22
Salut,
Pour tuer le temps je me suis mis à me coder un petit lecteur d'OGG utilisant un canvas pour afficher la progression et la modifier si besoin.
Il fonctionne mais me bouffe pas mal de ressources (entre 25 et 29% du proce)
Je pense que c'est lié au dessin constant de la progressbar en canvas que j'ai mis jsute après mon repeat.
Vu que la progression doit être constante, je ne vois pas comment faire autrement.
Si vous avez une idée.
Pour tuer le temps je me suis mis à me coder un petit lecteur d'OGG utilisant un canvas pour afficher la progression et la modifier si besoin.
Il fonctionne mais me bouffe pas mal de ressources (entre 25 et 29% du proce)
Je pense que c'est lié au dessin constant de la progressbar en canvas que j'ai mis jsute après mon repeat.
Vu que la progression doit être constante, je ne vois pas comment faire autrement.
Si vous avez une idée.
Code : Tout sélectionner
; OOg / Flac - Canvas Player by Ar-S
If InitSound() = 0
MessageRequester("Error", "Sound system is not available", 0)
End
EndIf
UseOGGSoundDecoder()
Enumeration GUI
#WIN
#BTPLAYPAUSE
#BTstop
#Canvastime
#ZIK
#AFFICH
#F
#T
EndEnumeration
Global.s Fichier = "piano.ogg"
SON = LoadSound(#ZIK,Fichier)
Global F = LoadFont(#F, "Arial", 10)
#PLAY = 1
#PAUSE = 0
#RESUME = 2
#STOP = 3
Global WX,WY,WL,WH ; Position taille fenetre
Global LC,HC,XC,YC ; Position taille Canvas
Global Li,Hi,Xi,Yi ; Position taille image lecture
Global DureeSON = SoundLength(#ZIK, #PB_Sound_Millisecond)
Global Duree_EN_SECONDE = DureeSON / 1000
Global.b JOUE
Global En_Minutes = Duree_EN_SECONDE/60
Global En_Sec = Duree_EN_SECONDE%60
Global.s Duree_Totale
; Ajout des 0 pour l'esthétique
If En_Minutes < 10
EM.s = "0" + Str(En_Minutes) + "m"
Else
EM.s = Str(En_Minutes) + "m"
EndIf
If En_Sec < 10
ES.s = "0" + Str(En_Sec) + "s"
Else
ES.s = Str(En_Sec) + "s"
EndIf
Duree_Totale = EM + ES
Fichier = RemoveString(Fichier,GetExtensionPart(fichier),0)
JOUE = #STOP
WX = #PB_Ignore
WY = #PB_Ignore
WL = 600
WH = 400
LC = WL
HC = 40
Li = 1
Hi = 20
Xi = 0
Yi = 0
; Barre de progression et %
Macro DrawBar(L)
StartDrawing(CanvasOutput(#Canvastime))
Box(0,0,LC,HC,$0)
Box(0,10,L,20,$00ff00)
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(F)
If BarPOS/6 <= 93
XX = BarPOS+5
CC = $00CCFF
Else
XX = BarPOS-35
CC = $0
EndIf
DrawText(XX, 10, Str(BarPOS/6) + " %", CC)
StopDrawing()
EndMacro
Procedure Quitte()
Exit = 1
EndProcedure
If OpenWindow(#win, WX,WY,WL,WH,"Lecteur",#PB_Window_SystemMenu)
StringGadget(#AFFICH,0,0,WL,25,"",#PB_String_ReadOnly)
ButtonGadget(#BTPLAYPAUSE, 0,85,100,30,"Jouer")
ButtonGadget(#BTSTOP, 101,85,100,30,"Stop")
CanvasGadget(#Canvastime,0,40,LC,HC,#PB_Canvas_ClipMouse)
StartDrawing(CanvasOutput(#Canvastime))
Box(0,0,LC,HC,$0)
StopDrawing()
Repeat
If SoundStatus(#zik) = #PB_Sound_Playing Or SoundStatus(#zik) = #PB_Sound_Paused
Posi_SON = GetSoundPosition(#ZIK, #PB_Sound_Millisecond)
; Ajout des 0 pour l'esthétique
SEC = Posi_SON / 1000
MIN = SEC/60
If MIN < 10
Minute.s = "0" + Str(MIN)
Else
Minute.s = Str(MIN)
EndIf
RESTE = SEC % 60
If RESTE < 10
Seconde.s = "0" + Str(RESTE)
Else
Seconde.s = Str(RESTE)
EndIf
Duree2.s = Minute + "m" + Seconde + "s"
SetGadgetText(#AFFICH, " >> " + Fichier + " : " + Duree2.s + " / " + Duree_Totale )
PlayPOS = (Posi_SON * DureeSON) /LC
BarPOS.f = Posi_SON / DureeSON * LC
DrawBar(BarPOS)
ElseIf SoundStatus(#ZIK) = #PB_Sound_Stopped
Posi_SON = 0
DrawBar(BarPOS)
EndIf
Select WaitWindowEvent(1)
Case #PB_Event_Gadget
Select EventGadget()
Case #BTstop
JOUE = #STOP
StopSound(#zik)
SetSoundPosition(#zik,0)
BarPOS = 0
Case #BTPLAYPAUSE
If JOUE = #STOP
JOUE = #PLAY
SetGadgetText(#BTPLAYPAUSE,"Lecture en cours")
PlaySound(#zik,#PB_Sound_Millisecond,80)
ElseIf JOUE = #PLAY
JOUE = #PAUSE
SetGadgetText(#BTPLAYPAUSE,"Lecture en pause")
PauseSound(#ZIK)
ElseIf JOUE = #PAUSE
JOUE = #RESUME
SetGadgetText(#BTPLAYPAUSE,"Lecture en cours")
ResumeSound(#ZIK)
ElseIf JOUE = #RESUME
JOUE = #PAUSE
SetGadgetText(#BTPLAYPAUSE,"Lecture en pause")
PauseSound(#ZIK)
EndIf
Case #Canvastime
Select EventType()
Case #PB_EventType_MouseEnter
SetGadgetAttribute(#Canvastime, #PB_Canvas_Cursor, #PB_Cursor_Hand)
Case #PB_EventType_MouseLeave
SetGadgetAttribute(#Canvastime, #PB_Canvas_Cursor, #PB_Cursor_Default)
Case #PB_EventType_LeftButtonDown
Xcurs = GetGadgetAttribute(#Canvastime,#PB_Canvas_MouseX)
BarPOS = Xcurs ; DrawBar(Xcurs)
NewPos = Xcurs * (DureeSON/LC)
SetSoundPosition(#ZIK, NewPos, #PB_Sound_Millisecond)
EndSelect
EndSelect
Case #PB_Event_CloseWindow
Exit=1
EndSelect
Until exit = 1
EndIf
End