Page 1 sur 1

créer un lecteur genre VLC

Publié : dim. 16/déc./2007 13:32
par dimension4
Bonjour, alors voila j'aimerai crée un lecteur de musique ( voir plus si possibilité ). Alors déjà je m'aide du programme déjà integré dans l'aide je le prends , mais je n'arrive pas a mettre une TrackBarGadget à la place du Text gadget pour le temps. :cry:


voila je sais pas si vous avez compris ma demande mais merci de m'aider,


amicalement,

Publié : dim. 16/déc./2007 14:36
par poshu
balance ton code on te dira ce qui ne va pas.

Publié : dim. 16/déc./2007 14:48
par dimension4
alors en fait j'ai essaye de remplacer un TextGadget, qui est utilisé pour le temps de lecture d'une piste, par un TrackbarGaget, mais je n'y arrive pas. voici mon code modifié (l'original se trouve dans l'aide de PureBasic), merci de votre aide :

Code : Tout sélectionner

NbCDDrives = InitAudioCD()

If NbCDDrives = 0
  MessageRequester("Error", "No CD Audio drives found...", 0)
  End
EndIf

Global Null$

Procedure.s GetHourFormat(LengthInSeconds)
  Minutes = LengthInSeconds/60
  Seconds = LengthInSeconds-Minutes*60
  If Seconds < 10 : Null$ = "0" : Else : Null$ = "" : EndIf

  ProcedureReturn Str(Minutes)+":"+Null$+Str(Seconds)
EndProcedure

; Initialize constants for easier code reading
;
#GADGET_Play   = 0
#GADGET_Stop   = 1
#GADGET_Eject  = 2
#GADGET_Close  = 3
#GADGET_Select = 4
#GADGET_Status = 5
#GADGET_Time   = 6
#GADGET_AudioCDDrive = 7
#GADGET_SelectDrive  = 8

If OpenWindow(0, 100, 200, 265, 144, "PureBasic - AudioCD Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

  If CreateGadgetList(WindowID(0))
    ButtonGadget  (#GADGET_Play   ,  10, 10, 60 , 24, "Play")
    ButtonGadget  (#GADGET_Stop   ,  70, 10, 60 , 24, "Stop")
    ButtonGadget  (#GADGET_Eject  , 130, 10, 60 , 24, "Ouvrir")
    ButtonGadget  (#GADGET_Close  , 190, 10, 60 , 24, "Fermer")
    ComboBoxGadget(#GADGET_Select ,  10, 43, 240, 400)
    TextGadget    (#GADGET_Status ,  10, 70, 180, 16, "Status: stopped")
    TrackBarGadget    (#GADGET_Time   , 10, 100, 240, 30, "")

    TextGadget    (#GADGET_AudioCDDrive,  10, 94, 140,  24, "Select the CD-Audio drive :")
    ComboBoxGadget(#GADGET_SelectDrive , 150, 90,  40, 200)

    For k=1 To NbCDDrives
      UseAudioCD(k-1)
      AddGadgetItem(#GADGET_SelectDrive, -1, Left(AudioCDName(),2))
    Next
    SetGadgetState(#GADGET_SelectDrive, 0)
    UseAudioCD(0)

    If NbCDDrives = 1
      DisableGadget(#GADGET_SelectDrive, 1)
    EndIf
  EndIf

  Gosub RefreshCD

  Repeat
    Repeat
      EventID = WindowEvent()  ; This time we use the WindowEvent(), non-blocking command to allow time refreshing

      If EventID = #PB_Event_Gadget
        Select EventGadget() 

          Case #GADGET_Play
            CurrentTrack = GetGadgetState(4)+1
            PlayAudioCD(CurrentTrack, CurrentTrack)
            
          Case #GADGET_Stop
            StopAudioCD()

          Case #GADGET_Eject
            EjectAudioCD(1)

          Case #GADGET_Close
            EjectAudioCD(0)

          Case #GADGET_SelectDrive
            UseAudioCD(GetGadgetState(#GADGET_SelectDrive))
            Gosub RefreshCD

        EndSelect

      Else
        If EventID = #PB_Event_CloseWindow : Quit = 1 : EndIf   
      EndIf
    Until EventID = 0

    Delay(20) ; Wait 20 ms, which is a long period for the processor, to don't steal the whole CPU power
              ; for our little application :)

    CurrentTrack = AudioCDStatus()
    If CurrentTrack > 0
      SetGadgetText(#GADGET_Status, "Playing Track "+Str(CurrentTrack)+" (Length: "+GetHourFormat(AudioCDTrackLength(CurrentTrack))+")")
      SetGadgetText(#GADGET_Time, "Time: "+GetHourFormat(AudioCDTrackSeconds()))
      DisableGadget(#GADGET_Play, 1)
      DisableGadget(#GADGET_Stop, 0)
      DisableGadget(#GADGET_Select, 0)
    Else
      SetGadgetText(#GADGET_Status, "Status: Stopped")
      SetGadgetText(#GADGET_Time, "")
      DisableGadget(#GADGET_Play, 0)
      DisableGadget(#GADGET_Stop, 1)

      If CurrentTrack = -1 ; CD Drive not ready
        DisableGadget(#GADGET_Select, 1)
      Else
        DisableGadget(#GADGET_Select, 0)
      EndIf
    EndIf

  Until Quit = 1

EndIf

For k=0 To NbCDDrives-1    ; Stop all the CD drives, if some are playing together
  UseAudioCD(k)
  StopAudioCD()
Next

End 

;-----------------------------------------------------------------
;  SubRoutines
;

RefreshCD:
  ClearGadgetItemList(#GADGET_Select)

  NbAudioTracks = AudioCDTracks()
  For k=1 To NbAudioTracks
    AddGadgetItem(#GADGET_Select, -1, "Track "+Str(k))
  Next
  SetGadgetState(#GADGET_Select, 0)
Return

    Publié : dim. 16/déc./2007 14:57
    par poshu
    Normalement, quand je sais d'où vient l'erreur (ce qui arrive assez rarement), je répond.
    Là, un seul mot me vient en tête: RTFM!!!
    Et fais un effort è_é

    Publié : dim. 16/déc./2007 16:16
    par Eric
    Voila ton Code modifié et fonctionnel ;

    Code : Tout sélectionner

    NbCDDrives = InitAudioCD() 
    
    If NbCDDrives = 0 
      MessageRequester("Error", "No CD Audio drives found...", 0) 
      End 
    EndIf 
    
    Global Null$ 
    
    Procedure.s GetHourFormat(LengthInSeconds) 
      Minutes = LengthInSeconds/60 
      Seconds = LengthInSeconds-Minutes*60 
      If Seconds < 10 : Null$ = "0" : Else : Null$ = "" : EndIf 
    
      ProcedureReturn Str(Minutes)+":"+Null$+Str(Seconds) 
    EndProcedure 
    
    ; Initialize constants for easier code reading 
    ; 
    #GADGET_Play   = 0 
    #GADGET_Stop   = 1 
    #GADGET_Eject  = 2 
    #GADGET_Close  = 3 
    #GADGET_Select = 4 
    #GADGET_Status = 5 
    #GADGET_Time   = 6 
    #GADGET_AudioCDDrive = 7 
    #GADGET_SelectDrive  = 8 
    
    If OpenWindow(0, 100, 200, 265, 144, "PureBasic - AudioCD Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
    
      If CreateGadgetList(WindowID(0)) 
        ButtonGadget  (#GADGET_Play   ,  10, 10, 60 , 24, "Play") 
        ButtonGadget  (#GADGET_Stop   ,  70, 10, 60 , 24, "Stop") 
        ButtonGadget  (#GADGET_Eject  , 130, 10, 60 , 24, "Ouvrir") 
        ButtonGadget  (#GADGET_Close  , 190, 10, 60 , 24, "Fermer") 
        ComboBoxGadget(#GADGET_Select ,  10, 43, 240, 400) 
        TextGadget    (#GADGET_Status ,  10, 70, 180, 16, "Status: stopped") 
        TrackBarGadget(#GADGET_Time   , 10, 110, 240, 30, 0,100) 
    
        TextGadget    (#GADGET_AudioCDDrive,  10, 94, 140,  24, "Select the CD-Audio drive :") 
        ComboBoxGadget(#GADGET_SelectDrive , 150, 90,  40, 200) 
    
        For k=1 To NbCDDrives 
          UseAudioCD(k-1) 
          AddGadgetItem(#GADGET_SelectDrive, -1, Left(AudioCDName(),2)) 
        Next 
        SetGadgetState(#GADGET_SelectDrive, 0) 
        UseAudioCD(0) 
    
        If NbCDDrives = 1 
          DisableGadget(#GADGET_SelectDrive, 1) 
        EndIf 
      EndIf 
    
      Gosub RefreshCD 
    
      Repeat 
        Repeat 
          EventID = WindowEvent()  ; This time we use the WindowEvent(), non-blocking command to allow time refreshing 
    
          If EventID = #PB_Event_Gadget 
            Select EventGadget() 
    
              Case #GADGET_Play 
                CurrentTrack = GetGadgetState(4)+1 
                PlayAudioCD(CurrentTrack, CurrentTrack) 
                
              Case #GADGET_Stop 
                StopAudioCD() 
    
              Case #GADGET_Eject 
                EjectAudioCD(1) 
    
              Case #GADGET_Close 
                EjectAudioCD(0) 
    
              Case #GADGET_SelectDrive 
                UseAudioCD(GetGadgetState(#GADGET_SelectDrive)) 
                Gosub RefreshCD 
    
            EndSelect 
    
          ElseIf EventID = #PB_Event_CloseWindow 
           	Quit = 1     
          EndIf 
        Until Quit=1 
    
        Delay(20) ; Wait 20 ms, which is a long period for the processor, to don't steal the whole CPU power 
                  ; for our little application :) 
    
        CurrentTrack = AudioCDStatus() 
        If CurrentTrack > 0 
          SetGadgetText(#GADGET_Status, "Playing Track "+Str(CurrentTrack)+" (Length: "+GetHourFormat(AudioCDTrackLength(CurrentTrack))+")") 
          SetGadgetText(#GADGET_Time, "Time: "+GetHourFormat(AudioCDTrackSeconds())) 
          DisableGadget(#GADGET_Play, 1) 
          DisableGadget(#GADGET_Stop, 0) 
          DisableGadget(#GADGET_Select, 0) 
        Else 
          SetGadgetText(#GADGET_Status, "Status: Stopped") 
          SetGadgetText(#GADGET_Time, "") 
          DisableGadget(#GADGET_Play, 0) 
          DisableGadget(#GADGET_Stop, 1) 
    
          If CurrentTrack = -1 ; CD Drive not ready 
            DisableGadget(#GADGET_Select, 1) 
          Else 
            DisableGadget(#GADGET_Select, 0) 
          EndIf 
        EndIf 
    
      Until Quit = 1 
    
    EndIf 
    
    For k=0 To NbCDDrives-1    ; Stop all the CD drives, if some are playing together 
      UseAudioCD(k) 
      StopAudioCD() 
    Next 
    
    End 
    
    ;----------------------------------------------------------------- 
    ;  SubRoutines 
    ; 
    
    RefreshCD: 
      ClearGadgetItemList(#GADGET_Select) 
    
      NbAudioTracks = AudioCDTracks() 
      For k=1 To NbAudioTracks 
        AddGadgetItem(#GADGET_Select, -1, "Track "+Str(k)) 
      Next 
      SetGadgetState(#GADGET_Select, 0) 
    Return

    La lecture de la Doc est trés importante, alors il ne faut pas courrir pour écrire un code.

    Eric
    Eric

    Publié : dim. 16/déc./2007 18:08
    par poshu
    Plus que de ne pas courir pour écrire un code, lire les erreurs lors de la compilation suffit. Y'a vraiment eu AUCUN effort sur ce coup >_>

    Publié : dim. 16/déc./2007 18:12
    par venom
    bonjour,

    de toute façon avec purebasic de base ( sans library ) on ne peut pas deplacer du mp3 a l'endroit qu'on veut. du moin il me semble :? .

    voici un code qui renvoie bien de la video mais si on met un mp3 et bien sa ne fonctionne pas tester une video et ensuite un mp3 vous verrez :wink: .

    Code : Tout sélectionner

    InitMovie()
    ;- Window Constants
    Enumeration
      #Window_0
    EndEnumeration
    
    ;- Gadget Constants
    Enumeration
      #Button_0
      #Button_1
      #TrackBar_0
    EndEnumeration
    
      If OpenWindow(#Window_0, 0, 0, 800, 385, "test trackbar",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar )
        If CreateGadgetList(WindowID(#Window_0))
          ButtonGadget(#Button_0, 550, 10, 100, 25, "ouvrir")
          ButtonGadget(#Button_1, 650, 10, 100, 25, "lecture")
          TrackBarGadget(#TrackBar_0, 550, 45, 210, 25, 0, 500)
          
        EndIf
      EndIf
    
      Repeat
       EventID = WaitWindowEvent()
        If EventID = #PB_Event_Gadget 
          Select EventGadget()
          
           Case #Button_0
            NomFichier$ = OpenFileRequester("Titre", "", "Videos et mp3|*.avi;*.mpg;*.wav;*.wmv;*.mp3", 0)
            If NomFichier$
              LoadMovie(1, NomFichier$)
            EndIf 
            SetWindowTitle(#Window_0, GetFilePart(NomFichier$)) 
            longueur=MovieLength(1);<---- apres avoir ouvert le fichier on donne sa longueur
    
           
           Case #Button_1
            If MovieStatus(1) = 0
              PlayMovie(1, WindowID(#Window_0))
            EndIf
            
           Case #TrackBar_0
            MovieSeek(1,GetGadgetState(#TrackBar_0)*longueur/500);<--- a chaque clique sur la trackbargadget on renvoie 
            ;la position de la trackbar ( entre 0 et 500 ). que l'on multiplie par la longueur du fichier et qu'on 
            ;redivise par la longueur de la trackbar
            
            
          
          EndSelect
        EndIf
      Until EventID = #PB_Event_CloseWindow
    voila



    @++

    Publié : dim. 16/déc./2007 18:15
    par dimension4
    excusez-moi mais j'ai du m'absenter ! merci a vous de m'avoir aider c'est vraiment gentil :lol: