Differenze tra le versioni di "Eseguire file audio mediante le funzioni esterne del API di VLC"

Da Gambas-it.org - Wikipedia.
 
(14 versioni intermedie di uno stesso utente non sono mostrate)
Riga 8: Riga 8:
 
E' possibile eseguire dati audio anche direttamente da internet.
 
E' possibile eseguire dati audio anche direttamente da internet.
  
 
+
Per creare in Gambas un'applicazione con la presente risorsa, si dovrà installare e richiamare la libreria condivisa "''libvlc.so.5.6.1'' ".
Per creare in Gambas un'applicazione con la presente risorsa, si dovrà installare e richiamare la libreria dinamica e condivisa ''libvlc.so.5.5.0''.
 
  
 
===Esempio con applicazione grafica===
 
===Esempio con applicazione grafica===
Riga 17: Riga 16:
 
    
 
    
 
   
 
   
  Library "libvlc:5.5.0"
+
  Library "libvlc:5.6.1"
 
   
 
   
 
  Private Enum libvlc_NothingSpecial = 0,
 
  Private Enum libvlc_NothingSpecial = 0,
        libvlc_Opening,
+
              libvlc_Opening,
        libvlc_Buffering,
+
              libvlc_Buffering,
        libvlc_Playing,
+
              libvlc_Playing,
        libvlc_Paused,
+
              libvlc_Paused,
        libvlc_Stopped,
+
              libvlc_Stopped,
        libvlc_Ended,
+
              libvlc_Ended,
        libvlc_Error
+
              libvlc_Error
 
   
 
   
 
  <FONT color=gray>' ''libvlc_instance_t * libvlc_new (int argc, const char *const *argv)''
 
  <FONT color=gray>' ''libvlc_instance_t * libvlc_new (int argc, const char *const *argv)''
Riga 50: Riga 49:
 
  <FONT color=gray>' ''libvlc_time_t libvlc_media_player_get_length(libvlc_media_player_t *, libvlc_exception_t *)''
 
  <FONT color=gray>' ''libvlc_time_t libvlc_media_player_get_length(libvlc_media_player_t *, libvlc_exception_t *)''
 
  ' ''Get the current movie length (in ms).''</font>
 
  ' ''Get the current movie length (in ms).''</font>
  Private Extern libvlc_media_player_get_length(p_mi As Pointer, l_ex As Pointer) As Integer
+
  Private Extern libvlc_media_player_get_length(p_mi As Pointer, l_ex As Pointer) As Long
 
   
 
   
 
  <FONT color=gray>' ''libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)''
 
  <FONT color=gray>' ''libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)''
 
  ' ''Get the current movie time (in ms).''</font>
 
  ' ''Get the current movie time (in ms).''</font>
  Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Integer
+
  Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Long
 
   
 
   
 
  <FONT color=gray>' ''libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)''
 
  <FONT color=gray>' ''libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)''
Riga 77: Riga 76:
 
   
 
   
 
   
 
   
  '''Public''' Sub Button1_Click()
+
  Public Sub Button1_Click()
 
   
 
   
 
   Dim m As Pointer
 
   Dim m As Pointer
 
 
 
      
 
      
 
  <FONT color=gray>' ''Inizializza la libreria VLC:''</font>
 
  <FONT color=gray>' ''Inizializza la libreria VLC:''</font>
  inst = libvlc_new(0, Null)
+
  inst = libvlc_new(0, Null)
 
      
 
      
 
  <FONT color=gray>' ''Crea un nuovo oggetto multimedia:''</font>
 
  <FONT color=gray>' ''Crea un nuovo oggetto multimedia:''</font>
  m = libvlc_media_new_path(inst, "<FONT color=gray>''/percorso/del/file/audio''</font>")
+
  m = libvlc_media_new_path(inst, "<FONT color=darkgreen>''/percorso/del/file/audio''</font>")
 
      
 
      
 
  <FONT color=gray>' ''Crea un media player:''</font>
 
  <FONT color=gray>' ''Crea un media player:''</font>
  mp = libvlc_media_player_new_from_media(m)
+
  mp = libvlc_media_player_new_from_media(m)
 +
 
 +
<FONT color=gray>' ''Chiude il descrittore dell'oggetto media:''</font>
 +
  libvlc_media_release(m)
 
      
 
      
 
   <FONT color=gray>' ''Avvia l'esecuzione del file audio da parte del media player:''</font>
 
   <FONT color=gray>' ''Avvia l'esecuzione del file audio da parte del media player:''</font>
  libvlc_media_player_play(mp)
+
  libvlc_media_player_play(mp)
 +
 +
  Repeat
 +
    TextLabel1.Text = "Durata: " & Str(Time(0, 0, 0, libvlc_media_player_get_length(mp, 0)))
 +
    TextLabel2.Text = "&lt;FONT Color=red>" & Str(Time(0, 0, 0, libvlc_media_player_get_time(mp)))
 +
    Wait 0.01
 +
  Until libvlc_media_player_get_state(mp) > libvlc_Paused
 
   
 
   
  Do
+
<FONT color=gray>' ''Rilascia e chiude il media player:''</font>
    TextLabel1.Text = "Durata: " & Str(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_length(mp, 0)))
+
  libvlc_media_player_release(mp)
    TextLabel2.Text = "&lt;FONT Color=red>" & Str(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_time(mp)))
 
    Wait 0.01
 
  Loop Until libvlc_media_player_get_state(mp) > libvlc_Paused
 
 
   
 
   
  Chiude()
+
<FONT color=gray>' ''Chiude la libreria VLC:''</font>
 +
  libvlc_release(inst)
 
   
 
   
  '''End'''
+
  End
 
   
 
   
 
   
 
   
  '''Public''' Sub Button2_Click()
+
  Public Sub Button2_Click()
 
   
 
   
 
  <FONT color=gray>' ''Arresta l'esecuzione del file audio:''</font>
 
  <FONT color=gray>' ''Arresta l'esecuzione del file audio:''</font>
  libvlc_media_player_stop(mp)
+
  libvlc_media_player_stop(mp)
 
'''End'''
 
 
 
   
 
   
  '''Private''' Procedure Chiude()
+
  End
   
 
<FONT color=gray>' ''Rilascia e chiude il media player:''</font>
 
  libvlc_media_player_release(mp)
 
   
 
<FONT color=gray>' ''Chiude il descrittore dell'oggetto media:''</font>
 
  libvlc_media_release(m)
 
 
 
<FONT color=gray>' ''Chiude la libreria VLC:''</font>
 
  libvlc_release(inst)
 
   
 
'''End'''
 
 
   
 
   
 
   
 
   
  '''Public''' Sub ToggleButton1_Click()
+
  Public Sub ToggleButton1_Click()
 
   
 
   
 
  <FONT color=gray>' ''Pone in pausa o riprende (se già in pausa) l'esecuzione del file audio:''</font>
 
  <FONT color=gray>' ''Pone in pausa o riprende (se già in pausa) l'esecuzione del file audio:''</font>
  libvlc_media_player_pause(mp)
+
  libvlc_media_player_pause(mp)
 
   
 
   
  '''End'''
+
  End
 
 
 
 
 
In quest'altro esempio mostreremo un effetto video (''Spectrum analyzer'') di VLC, che rappresenta un "Analizzatore di spettro", all'interno di una ''DrawingArea''
 
In quest'altro esempio mostreremo un effetto video (''Spectrum analyzer'') di VLC, che rappresenta un "Analizzatore di spettro", all'interno di una ''DrawingArea''
 
  Private inst As Pointer
 
  Private inst As Pointer
 
  Private mp As Pointer
 
  Private mp As Pointer
 
+
 
 
   
 
   
  Library "libvlc:5.5.0"
+
  Library "libvlc:5.6.1"
 
   
 
   
 
  Private Enum libvlc_NothingSpecial = 0,
 
  Private Enum libvlc_NothingSpecial = 0,
        libvlc_Opening,
+
              libvlc_Opening,
        libvlc_Buffering,
+
              libvlc_Buffering,
        libvlc_Playing,
+
              libvlc_Playing,
        libvlc_Paused,
+
              libvlc_Paused,
        libvlc_Stopped,
+
              libvlc_Stopped,
        libvlc_Ended,
+
              libvlc_Ended,
        libvlc_Error
+
              libvlc_Error
 
   
 
   
 
  <FONT color=gray>' ''libvlc_instance_t * libvlc_new (int argc, const char *const *argv)''
 
  <FONT color=gray>' ''libvlc_instance_t * libvlc_new (int argc, const char *const *argv)''
Riga 177: Riga 166:
 
  <FONT color=gray>' ''libvlc_time_t libvlc_media_player_get_length(libvlc_media_player_t *, libvlc_exception_t *)''
 
  <FONT color=gray>' ''libvlc_time_t libvlc_media_player_get_length(libvlc_media_player_t *, libvlc_exception_t *)''
 
  ' ''Get the current movie length (in ms).''</font>
 
  ' ''Get the current movie length (in ms).''</font>
  Private Extern libvlc_media_player_get_length(p_mi As Pointer, l_ex As Pointer) As Integer
+
  Private Extern libvlc_media_player_get_length(p_mi As Pointer, l_ex As Pointer) As Long
 
   
 
   
 
  <FONT color=gray>' ''libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)''
 
  <FONT color=gray>' ''libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)''
 
  ' ''Get the current movie time (in ms).''</font>
 
  ' ''Get the current movie time (in ms).''</font>
  Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Integer
+
  Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Long
 
   
 
   
 
  <FONT color=gray>' ''libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)''
 
  <FONT color=gray>' ''libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)''
Riga 204: Riga 193:
 
   
 
   
 
   
 
   
  '''Public''' Sub Button1_Click()
+
  Public Sub Button1_Click()
 
   
 
   
 
   Dim ss As String[]
 
   Dim ss As String[]
Riga 210: Riga 199:
 
   Dim id As Integer
 
   Dim id As Integer
 
    
 
    
  ss = ["--audio-visual=visual", "--effect-list=spectrum"]
+
  ss = ["--audio-visual=visual", "--effect-list=spectrum"]
 
    
 
    
 
  <FONT color=gray>' ''Inizializza la libreria VLC:''</font>
 
  <FONT color=gray>' ''Inizializza la libreria VLC:''</font>
  inst = libvlc_new(ss.Count, ss)
+
  inst = libvlc_new(ss.Count, ss)
 
      
 
      
 
  <FONT color=gray>' ''Crea un nuovo oggetto multimedia:''</font>
 
  <FONT color=gray>' ''Crea un nuovo oggetto multimedia:''</font>
  m = libvlc_media_new_path(inst, "<FONT color=gray>''/percorso/del/file/audio''</font>")
+
  m = libvlc_media_new_path(inst, "<FONT color=darkgreen>''/percorso/del/file/audio''</font>")
 
      
 
      
 
  <FONT color=gray>' ''Crea un media player:''</font>
 
  <FONT color=gray>' ''Crea un media player:''</font>
  mp = libvlc_media_player_new_from_media(m)
+
  mp = libvlc_media_player_new_from_media(m)
 +
   
 +
<FONT color=gray>' ''Chiude il descrittore dell'oggetto media:''</font>
 +
  libvlc_media_release(m)
 
    
 
    
 
  <FONT color=gray>' ''Per far mostrare l'effetto video "Analizzatore di spettro" nella "DrawingArea", ricaviamo il suo identificativo:''</font>
 
  <FONT color=gray>' ''Per far mostrare l'effetto video "Analizzatore di spettro" nella "DrawingArea", ricaviamo il suo identificativo:''</font>
  id = DrawingArea1.Id
+
  id = DrawingArea1.Id
 
    
 
    
 
  <FONT color=gray>' ''Passiamo l'identificativo della finestra, nella quale dovrà essere mostrato l'effetto "Spectrum analyzer":''</font>
 
  <FONT color=gray>' ''Passiamo l'identificativo della finestra, nella quale dovrà essere mostrato l'effetto "Spectrum analyzer":''</font>
  libvlc_media_player_set_xwindow(mp, id)
+
  libvlc_media_player_set_xwindow(mp, id)
 
      
 
      
 
   <FONT color=gray>' ''Avvia l'esecuzione del file audio da parte del media player:''</font>
 
   <FONT color=gray>' ''Avvia l'esecuzione del file audio da parte del media player:''</font>
  libvlc_media_player_play(mp)
+
  libvlc_media_player_play(mp)
 
   
 
   
  Do
+
  Repeat
    TextLabel1.Text = "Durata: " & Str(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_length(mp, 0)))
+
    TextLabel1.Text = "Durata: " & Str(Time(0, 0, 0, libvlc_media_player_get_length(mp, 0)))
    TextLabel2.Text = "&lt;FONT Color=red>" & Str(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_time(mp)))
+
    TextLabel2.Text = "&lt;FONT Color=red>" & Str(Time(0, 0, 0, libvlc_media_player_get_time(mp)))
    Wait 0.01
+
    Wait 0.01
  Loop Until libvlc_media_player_get_state(mp) > libvlc_Paused
+
  Until libvlc_media_player_get_state(mp) > libvlc_Paused
 
   
 
   
  Chiude()
+
<FONT color=gray>' ''Rilascia e chiude il media player:''</font>
 +
  libvlc_media_player_release(mp)
 +
 
 +
<FONT color=gray>' ''Chiude la libreria VLC:''</font>
 +
  libvlc_release(inst)
 
   
 
   
  '''End'''
+
  End
 
   
 
   
 
   
 
   
  '''Public''' Sub Button2_Click()
+
  Public Sub Button2_Click()
 
   
 
   
 
  <FONT color=gray>' ''Arresta l'esecuzione del file audio:''</font>
 
  <FONT color=gray>' ''Arresta l'esecuzione del file audio:''</font>
  libvlc_media_player_stop(mp)
+
  libvlc_media_player_stop(mp)
 
   
 
   
  '''End'''
+
  End
 
   
 
   
 
   
 
   
  '''Private''' Procedure Chiude()
+
  Public Sub ToggleButton1_Click()
   
 
<FONT color=gray>' ''Rilascia e chiude il media player:''</font>
 
  libvlc_media_player_release(mp)
 
   
 
<FONT color=gray>' ''Chiude il descrittore dell'oggetto media:''</font>
 
  libvlc_media_release(m)
 
 
 
<FONT color=gray>' ''Chiude la libreria VLC:''</font>
 
  libvlc_release(inst)
 
   
 
'''End'''
 
 
 
'''Public''' Sub ToggleButton1_Click()
 
 
   
 
   
 
  <FONT color=gray>' ''Pone in pausa o riprende (se già in pausa) l'esecuzione del file audio:''</font>
 
  <FONT color=gray>' ''Pone in pausa o riprende (se già in pausa) l'esecuzione del file audio:''</font>
  libvlc_media_player_pause(mp)
+
  libvlc_media_player_pause(mp)
 
   
 
   
  '''End'''
+
  End
 
 
 
 
 
Quest'altro esempio è più completo e complesso del precedente. La particolarità del codice seguente è che è possibile selezionare nel codice fino a 5 effetti grafici VLC.
 
Quest'altro esempio è più completo e complesso del precedente. La particolarità del codice seguente è che è possibile selezionare nel codice fino a 5 effetti grafici VLC.
 
  Private bt1 As Button
 
  Private bt1 As Button
Riga 285: Riga 265:
 
   
 
   
 
   
 
   
  Library "libvlc:5.5.0"
+
  Library "libvlc:5.6.1"
 
   
 
   
 
  Private Enum libvlc_NothingSpecial = 0, libvlc_Opening, libvlc_Buffering, libvlc_Playing,
 
  Private Enum libvlc_NothingSpecial = 0, libvlc_Opening, libvlc_Buffering, libvlc_Playing,
Riga 316: Riga 296:
 
  <FONT Color=gray>' ''libvlc_time_t libvlc_media_player_get_length(libvlc_media_player_t *, libvlc_exception_t *)''
 
  <FONT Color=gray>' ''libvlc_time_t libvlc_media_player_get_length(libvlc_media_player_t *, libvlc_exception_t *)''
 
  ' ''Get the current movie length (in ms).''</font>
 
  ' ''Get the current movie length (in ms).''</font>
  Private Extern libvlc_media_player_get_length(p_mi As Pointer, l_ex As Pointer) As Integer
+
  Private Extern libvlc_media_player_get_length(p_mi As Pointer, l_ex As Pointer) As Long
 
   
 
   
 
  <FONT Color=gray>' ''libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)''
 
  <FONT Color=gray>' ''libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)''
 
  ' ''Get the current movie time (in ms).''</font>
 
  ' ''Get the current movie time (in ms).''</font>
  Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Integer
+
  Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Long
 
   
 
   
 
  <FONT Color=gray>' ''libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)''
 
  <FONT Color=gray>' ''libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)''
Riga 343: Riga 323:
 
   
 
   
 
   
 
   
  '''Public''' Sub Form_Open()
+
  Public Sub Form_Open()
 
    
 
    
 
   Dim effetti, ss As String[]
 
   Dim effetti, ss As String[]
 
   Dim argc As Integer
 
   Dim argc As Integer
 
    
 
    
  GestioneOggetti()
+
  GestioneOggetti()
  effetti = ["dummy", "scope", "spectrum", "spectrometer", "vuMeter"]
+
  effetti = ["dummy", "scope", "spectrum", "spectrometer", "vuMeter"]
 
    
 
    
  ss = ["--audio", "--audio-visual=visual", "--effect-list=" & effetti[4], "--visual-80-bands", "--visual-peaks",  
+
  ss = ["--audio", "--audio-visual=visual", "--effect-list=" & effetti[4], "--visual-80-bands", "--visual-peaks",  
        "--width= 350", "--height=250", "--gain=1.000", "--no-xli"]
+
        "--width= 350", "--height=250", "--gain=1.000", "--no-xli"]
 
    
 
    
 
  <FONT Color=gray>' ''Indica quanti, e dunque, quali effetti, compresi nel vettore "ss" si vogliono utilizzare:''</font>
 
  <FONT Color=gray>' ''Indica quanti, e dunque, quali effetti, compresi nel vettore "ss" si vogliono utilizzare:''</font>
  argc = ss.Count
+
  argc = ss.Count
 
    
 
    
 
  <FONT Color=gray>' ''Inizializza la libreria VLC:''</font>
 
  <FONT Color=gray>' ''Inizializza la libreria VLC:''</font>
  inst = libvlc_new(argc, ss)
+
  inst = libvlc_new(argc, ss)
 
    
 
    
  '''End'''
+
  End
 
   
 
   
 
   
 
   
  '''Public''' Sub Button1_Click()
+
  Public Sub Button1_Click()
 
    
 
    
 
   Dim id As Integer
 
   Dim id As Integer
 
   Dim DrAr As DrawingArea
 
   Dim DrAr As DrawingArea
 
    
 
    
  With DrAr = New DrawingArea(Me)
+
  With DrAr = New DrawingArea(Me)
    .X = 10
+
    .X = 10
    .Y = 10
+
    .Y = 10
    .W = 350
+
    .W = 350
    .H = 250
+
    .H = 250
  End With
+
  End With
 
    
 
    
  bt1.Enabled = False
+
  bt1.Enabled = False
  tb.Enabled = True
+
  tb.Enabled = True
  tb.Value = False
+
  tb.Value = False
 
      
 
      
 
  <FONT Color=gray>' ''Crea un nuovo oggetto multimedia.''
 
  <FONT Color=gray>' ''Crea un nuovo oggetto multimedia.''
 
  ' ''Nel secondo argomento della funzione va specificato il percorso del file audio.''</font>
 
  ' ''Nel secondo argomento della funzione va specificato il percorso del file audio.''</font>
  m = libvlc_media_new_path(inst, fileaudio)
+
  m = libvlc_media_new_path(inst, fileaudio)
 
    
 
    
 
  <FONT Color=gray>' ''Crea un media player:''</font>
 
  <FONT Color=gray>' ''Crea un media player:''</font>
  mp = libvlc_media_player_new_from_media(m)
+
  mp = libvlc_media_player_new_from_media(m)
 +
 
 +
<FONT color=gray>' ''Chiude l'oggetto media:''</font>
 +
  libvlc_media_release(m)
 
    
 
    
 
  <FONT Color=gray>' ''Per far mostrare l'effetto VLC nella "DrawingArea", ricaviamo il suo identificativo:''</font>
 
  <FONT Color=gray>' ''Per far mostrare l'effetto VLC nella "DrawingArea", ricaviamo il suo identificativo:''</font>
  id = DrAr.Id
+
  id = DrAr.Id
 
    
 
    
 
  <FONT Color=gray>' ''Passiamo l'identificativo della finestra, nella quale dovrà essere mostrato l'effetto VLC:''</font>
 
  <FONT Color=gray>' ''Passiamo l'identificativo della finestra, nella quale dovrà essere mostrato l'effetto VLC:''</font>
  libvlc_media_player_set_xwindow(mp, id)
+
  libvlc_media_player_set_xwindow(mp, id)
 
    
 
    
 
  <FONT Color=gray>' ''Avvia l'esecuzione del file audio da parte del media player:''</font>
 
  <FONT Color=gray>' ''Avvia l'esecuzione del file audio da parte del media player:''</font>
  libvlc_media_player_play(mp)
+
  libvlc_media_player_play(mp)
 
    
 
    
  Do
+
  Repeat
    tl1.Text = "Durata: " & Str(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_length(mp, 0)))
+
    tl1.Text = "Durata: " & Str(Time(0, 0, 0, libvlc_media_player_get_length(mp, 0)))
    tl2.Text = "<&#070;ONT Color=red>" & Str(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_time(mp)))
+
    tl2.Text = "<&#070;ONT Color=red>" & Str(Time(0, 0, 0, libvlc_media_player_get_time(mp)))
    Wait 0.01
+
    Wait 0.01
  Loop Until libvlc_media_player_get_state(mp) > libvlc_Paused
+
  Until libvlc_media_player_get_state(mp) > libvlc_Paused
 
    
 
    
  mp = 0
+
  mp = 0
  bt1.Enabled = True
+
  bt1.Enabled = True
 
    
 
    
  '''End'''
+
  End
 
   
 
   
 
   
 
   
  '''Public''' Sub Button2_Click()
+
  Public Sub Button2_Click()
 
    
 
    
 
   Stop()
 
   Stop()
 
    
 
    
  '''End'''
+
  End
 
   
 
   
 
   
 
   
  '''Public''' Sub ToggleButton1_Click()
+
  Public Sub ToggleButton1_Click()
 
    
 
    
 
  <FONT Color=gray>' ''Pone in pausa o riprende (se già in pausa) l'esecuzione del file audio:''</font>
 
  <FONT Color=gray>' ''Pone in pausa o riprende (se già in pausa) l'esecuzione del file audio:''</font>
 
   libvlc_media_player_pause(mp)
 
   libvlc_media_player_pause(mp)
 
    
 
    
  '''End'''
+
  End
 
   
 
   
 
   
 
   
  '''Public''' Sub Form_Close()
+
  Public Sub Form_Close()
 
    
 
    
 
   If Object.IsValid(Me) Then Chiude()
 
   If Object.IsValid(Me) Then Chiude()
 
 
'''End'''
 
 
   
 
   
 +
End
 +
 +
 +
Public Sub Menu_Click()
 
   
 
   
'''Public''' Sub Menu_Click()
 
 
 
 
   Select Case Last.Name
 
   Select Case Last.Name
 
     Case "Apri"
 
     Case "Apri"
Riga 447: Riga 430:
 
       Chiude()
 
       Chiude()
 
   End Select
 
   End Select
 
+
  '''End'''
+
  End
 
   
 
   
 
   
 
   
  '''Private''' Procedure Chiude()
+
  Private Procedure Chiude()
 
    
 
    
 
   If mp > 0 Then
 
   If mp > 0 Then
Riga 460: Riga 443:
 
   Endif
 
   Endif
 
    
 
    
<FONT color=gray>' ''Chiude il descrittore dell'oggetto media:''</font>
 
  libvlc_media_release(m)
 
 
 
 
  <FONT Color=gray>' ''Chiude la libreria VLC:''</font>
 
  <FONT Color=gray>' ''Chiude la libreria VLC:''</font>
 
   libvlc_release(inst)
 
   libvlc_release(inst)
Riga 471: Riga 451:
 
   Endif
 
   Endif
 
    
 
    
  '''End'''
+
  End
 
   
 
   
 
   
 
   
  '''Private''' Procedure Stop()
+
  Private Procedure Stop()
 
    
 
    
 
   If mp > 0 Then
 
   If mp > 0 Then
Riga 486: Riga 466:
 
   tb.Value = False
 
   tb.Value = False
 
    
 
    
  '''End'''
+
  End
 
   
 
   
 
   
 
   
  '''Private''' Procedure GestioneOggetti()
+
  Private Procedure GestioneOggetti()
 
    
 
    
 
   Dim mn1, mn2 As Menu
 
   Dim mn1, mn2 As Menu
 
    
 
    
  With Me
+
  With Me
    .W = 400
+
    .W = 400
    .H = 370
+
    .H = 370
  End With
+
  End With
  With tl0 = New TextLabel(Me)
+
  With tl0 = New TextLabel(Me)
    .X = 10
+
    .X = 10
    .Y = 265
+
    .Y = 265
    .W = 350
+
    .W = 350
    .H = 20
+
    .H = 20
  End With
+
  End With
  With tl1 = New TextLabel(Me)
+
  With tl1 = New TextLabel(Me)
    .X = 10
+
    .X = 10
    .Y = tl0.Y + tl0.H
+
    .Y = tl0.Y + tl0.H
    .W = 120
+
    .W = 120
    .H = 18
+
    .H = 18
    .Alignment = Align.Top
+
    .Alignment = Align.Top
  End With
+
  End With
  With tl2 = New TextLabel(Me)
+
  With tl2 = New TextLabel(Me)
    .X = tl1.X + tl1.W + 30
+
    .X = tl1.X + tl1.W + 30
    .Y = tl0.Y + tl0.H
+
    .Y = tl0.Y + tl0.H
    .W = 120
+
    .W = 120
    .H = 18
+
    .H = 18
    .Alignment = Align.TopLeft
+
    .Alignment = Align.TopLeft
  End With
+
  End With
  With bt1 = New Button(Me) As "Button1"
+
  With bt1 = New Button(Me) As "Button1"
    .X = 10
+
    .X = 10
    .Y = 300
+
    .Y = 300
    .W = 300
+
    .W = 300
    .H = 40
+
    .H = 40
    .Foreground = Color.DarkGreen
+
    .Foreground = Color.DarkGreen
    .Text = "Esegui"
+
    .Text = "Esegui"
    .Enabled = False
+
    .Enabled = False
  End With
+
  End With
  With bt2 = New Button(Me) As "Button2"
+
  With bt2 = New Button(Me) As "Button2"
    .X = bt1.X + bt1.W + 20
+
    .X = bt1.X + bt1.W + 20
    .Y = 300
+
    .Y = 300
    .W = 50
+
    .W = 50
    .H = 40
+
    .H = 40
    .Foreground = Color.DarkRed
+
    .Foreground = Color.DarkRed
    .Text = "Stop"
+
    .Text = "Stop"
  End With
+
  End With
  With tb = New ToggleButton(Me) As "ToggleButton1"
+
  With tb = New ToggleButton(Me) As "ToggleButton1"
    .X = bt2.X
+
    .X = bt2.X
    .Y = 220
+
    .Y = 220
    .W = 50
+
    .W = 50
    .H = 40
+
    .H = 40
    .Text = "Pausa"
+
    .Text = "Pausa"
    .Enabled = False
+
    .Enabled = False
  End With
+
  End With
  With menu = New Menu(Me) As "Menu"
+
  With menu = New Menu(Me) As "Menu"
    .Caption = "File"
+
    .Caption = "File"
  End With
+
  End With
  With mn1 = New Menu(menu, False) As "Menu"
+
  With mn1 = New Menu(menu, False) As "Menu"
 
     .Caption = "Apri file..."
 
     .Caption = "Apri file..."
 
     .Name = "Apri"
 
     .Name = "Apri"
  End With
+
  End With
  With mn2 = New Menu(menu, False) As "Menu"
+
  With mn2 = New Menu(menu, False) As "Menu"
 
     .Caption = "Esci"
 
     .Caption = "Esci"
 
     .Name = "Esci"
 
     .Name = "Esci"
  End With
+
  End With
 
    
 
    
  '''End'''
+
  End
 
 
 
 
  
 
===Esempio con applicazione ''a riga di comando''===
 
===Esempio con applicazione ''a riga di comando''===
  Library "libvlc:5.5.0"
+
  Library "libvlc:5.6.1"
 
   
 
   
 
  Private Enum libvlc_NothingSpecial = 0,
 
  Private Enum libvlc_NothingSpecial = 0,
        libvlc_Opening,
+
              libvlc_Opening,
        libvlc_Buffering,
+
              libvlc_Buffering,
        libvlc_Playing,
+
              libvlc_Playing,
        libvlc_Paused,
+
              libvlc_Paused,
        libvlc_Stopped,
+
              libvlc_Stopped,
        libvlc_Ended,
+
              libvlc_Ended,
        libvlc_Error
+
              libvlc_Error
 
   
 
   
 
  <FONT color=gray>' ''libvlc_instance_t * libvlc_new (int argc, const char *const *argv)''
 
  <FONT color=gray>' ''libvlc_instance_t * libvlc_new (int argc, const char *const *argv)''
Riga 588: Riga 566:
 
  <FONT color=gray>' ''libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)''
 
  <FONT color=gray>' ''libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)''
 
  ' ''Get the current movie time (in ms).''</font>
 
  ' ''Get the current movie time (in ms).''</font>
  Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Integer
+
  Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Long
 
   
 
   
 
  <FONT color=gray>' ''libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)''
 
  <FONT color=gray>' ''libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)''
 
  ' ''Get current movie state.''</font>
 
  ' ''Get current movie state.''</font>
  Private Extern libvlc_media_player_get_state(p_mi As Pointer) As Integer
+
  Private Extern libvlc_media_player_get_state(p_mi As Pointer) As Long
 
    
 
    
 
  <FONT color=gray>' ''void libvlc_media_player_release (libvlc_media_player_t * p_mi)''
 
  <FONT color=gray>' ''void libvlc_media_player_release (libvlc_media_player_t * p_mi)''
Riga 607: Riga 585:
 
   
 
   
 
   
 
   
  '''Public''' Sub Main()
+
  Public Sub Main()
 
   
 
   
 
   Dim inst, m, mp As Pointer
 
   Dim inst, m, mp As Pointer
 
        
 
        
 
  <FONT color=gray>' ''Inizializza la libreria VLC:''</font>
 
  <FONT color=gray>' ''Inizializza la libreria VLC:''</font>
    inst = libvlc_new(0, Null)
+
  inst = libvlc_new(0, Null)
 
      
 
      
 
  <FONT color=gray>' ''Crea un nuovo oggetto multimedia:''</font>
 
  <FONT color=gray>' ''Crea un nuovo oggetto multimedia:''</font>
    m = libvlc_media_new_path(inst, "<FONT color=gray>''/percorso/del/file/audio''</font>")
+
  m = libvlc_media_new_path(inst, "<FONT color=darkgreen>''/percorso/del/file/audio''</font>")
 
      
 
      
 
  <FONT color=gray>' ''Crea un media player:''</font>
 
  <FONT color=gray>' ''Crea un media player:''</font>
    mp = libvlc_media_player_new_from_media(m)
+
  mp = libvlc_media_player_new_from_media(m)
   
+
 
 +
  libvlc_media_release(m)
 +
 
 
   <FONT color=gray>' ''Avvia l'esecuzione del file audio da parte del media player:''</font>
 
   <FONT color=gray>' ''Avvia l'esecuzione del file audio da parte del media player:''</font>
    libvlc_media_player_play(mp)
+
  libvlc_media_player_play(mp)
 
    While libvlc_media_player_get_state(mp) < libvlc_Stopped
 
      Write #File.Out, Str(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_time(mp))) & "\r"
 
    Wend
 
 
   
 
   
 +
  While libvlc_media_player_get_state(mp) < libvlc_Stopped
 +
    Write "\r" & Str(Time(0, 0, 0, libvlc_media_player_get_time(mp)))
 +
    Flush
 +
    White 0.01
 +
  Wend
 
   
 
   
 
  <FONT color=gray>' ''Va in chiusura:''</font>
 
  <FONT color=gray>' ''Va in chiusura:''</font>
    libvlc_media_player_release(mp)
+
  libvlc_media_player_release(mp)
    libvlc_media_release(m)
+
  libvlc_release(inst)
    libvlc_release(inst)
 
 
   
 
   
  '''End'''
+
  End
 
 
  
  

Versione attuale delle 05:57, 14 gen 2024

La libreria LibVLC mette a disposizione funzioni e risorse anche per eseguire file audio.

I file audio eseguibili sono i seguenti:

  • MP3;
  • OGG;
  • WAV;
  • WMA.

E' possibile eseguire dati audio anche direttamente da internet.

Per creare in Gambas un'applicazione con la presente risorsa, si dovrà installare e richiamare la libreria condivisa "libvlc.so.5.6.1 ".

Esempio con applicazione grafica

Mostriamo di seguito un semplice esempio, nel quale si potrà avviare, arrestare, porre in pausa e riprendere l'esecuzione del file audio:

Private inst As Pointer
Private mp As Pointer
 

Library "libvlc:5.6.1"

Private Enum libvlc_NothingSpecial = 0,
             libvlc_Opening,
             libvlc_Buffering,
             libvlc_Playing,
             libvlc_Paused,
             libvlc_Stopped,
             libvlc_Ended,
             libvlc_Error

' libvlc_instance_t * libvlc_new (int argc, const char *const *argv)
' Create And initialize a libvlc instance.
Private Extern libvlc_new(argc As Integer, argv As String[]) As Pointer

' libvlc_media_t * libvlc_media_new_path (libvlc_instance_t *p_instance, const char *path)
' Create a media for a certain file path.
Private Extern libvlc_media_new_path(p_instance As Pointer, path As String) As Pointer

' libvlc_media_player_t * libvlc_media_player_new_from_media (libvlc_media_t *p_md)
' Create a Media Player object from a Media.
Private Extern libvlc_media_player_new_from_media(p_md As Pointer) As Pointer

' int libvlc_media_player_play (libvlc_media_player_t * p_mi)
' Play the audio file.
Private Extern libvlc_media_player_play(p_mi As Pointer) As Integer

' void libvlc_media_player_stop (libvlc_media_player_t * p_mi)
' Stop the audio file.
Private Extern libvlc_media_player_stop(p_mi As Pointer)

' libvlc_time_t libvlc_media_player_get_length(libvlc_media_player_t *, libvlc_exception_t *)
' Get the current movie length (in ms).
Private Extern libvlc_media_player_get_length(p_mi As Pointer, l_ex As Pointer) As Long

' libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)
' Get the current movie time (in ms).
Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Long

' libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)
' Get current movie state.
Private Extern libvlc_media_player_get_state(p_mi As Pointer) As Integer

' void   libvlc_media_player_pause (libvlc_media_player_t *p_mi)
' Toggle pause.
Private Extern libvlc_media_player_pause(p_mi As Pointer)

' void libvlc_media_player_release (libvlc_media_player_t * p_mi)
' Release a media_player after use Decrement the reference count of a media player object.
Private Extern libvlc_media_player_release(p_mi As Pointer)

' void libvlc_media_release (libvlc_media_t *p_md)
' Decrement the reference count of a media descriptor object.
Private Extern libvlc_media_release(p_md As Pointer)

' libvlc_release (libvlc_instance_t * p_instance)
' Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.
Private Extern libvlc_release(p_instance As Pointer)


Public Sub Button1_Click()

 Dim m As Pointer
   
' Inizializza la libreria VLC:
 inst = libvlc_new(0, Null)
   
' Crea un nuovo oggetto multimedia:
 m = libvlc_media_new_path(inst, "/percorso/del/file/audio")
   
' Crea un media player:
 mp = libvlc_media_player_new_from_media(m)
 
' Chiude il descrittore dell'oggetto media:
 libvlc_media_release(m)
   
 ' Avvia l'esecuzione del file audio da parte del media player:
 libvlc_media_player_play(mp)

 Repeat
   TextLabel1.Text = "Durata: " & Str(Time(0, 0, 0, libvlc_media_player_get_length(mp, 0)))
   TextLabel2.Text = "<FONT Color=red>" & Str(Time(0, 0, 0, libvlc_media_player_get_time(mp)))
   Wait 0.01
 Until libvlc_media_player_get_state(mp) > libvlc_Paused

' Rilascia e chiude il media player:
 libvlc_media_player_release(mp)

' Chiude la libreria VLC:
 libvlc_release(inst)

End


Public Sub Button2_Click()

' Arresta l'esecuzione del file audio:
 libvlc_media_player_stop(mp)

End


Public Sub ToggleButton1_Click()

' Pone in pausa o riprende (se già in pausa) l'esecuzione del file audio:
 libvlc_media_player_pause(mp)

End

In quest'altro esempio mostreremo un effetto video (Spectrum analyzer) di VLC, che rappresenta un "Analizzatore di spettro", all'interno di una DrawingArea

Private inst As Pointer
Private mp As Pointer
  

Library "libvlc:5.6.1"

Private Enum libvlc_NothingSpecial = 0,
             libvlc_Opening,
             libvlc_Buffering,
             libvlc_Playing,
             libvlc_Paused,
             libvlc_Stopped,
             libvlc_Ended,
             libvlc_Error

' libvlc_instance_t * libvlc_new (int argc, const char *const *argv)
' Create And initialize a libvlc instance.
Private Extern libvlc_new(argc As Integer, argv As String[]) As Pointer

' libvlc_media_t * libvlc_media_new_path (libvlc_instance_t *p_instance, const char *path)
' Create a media for a certain file path.
Private Extern libvlc_media_new_path(p_instance As Pointer, path As String) As Pointer

' libvlc_media_player_t * libvlc_media_player_new_from_media (libvlc_media_t *p_md)
' Create a Media Player object from a Media.
Private Extern libvlc_media_player_new_from_media(p_md As Pointer) As Pointer

' void libvlc_media_player_set_xwindow (libvlc_media_player_t *p_mi, uint32_t drawable)
' Set an X Window System drawable where the media player should render its video output.
Private Extern libvlc_media_player_set_xwindow(p_mi As Pointer, drawable As Integer)

' int libvlc_media_player_play (libvlc_media_player_t * p_mi)
' Play the audio file.
Private Extern libvlc_media_player_play(p_mi As Pointer) As Integer

' void libvlc_media_player_stop (libvlc_media_player_t * p_mi)
' Stop the audio file.
Private Extern libvlc_media_player_stop(p_mi As Pointer)

' libvlc_time_t libvlc_media_player_get_length(libvlc_media_player_t *, libvlc_exception_t *)
' Get the current movie length (in ms).
Private Extern libvlc_media_player_get_length(p_mi As Pointer, l_ex As Pointer) As Long

' libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)
' Get the current movie time (in ms).
Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Long

' libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)
' Get current movie state.
Private Extern libvlc_media_player_get_state(p_mi As Pointer) As Integer

' void   libvlc_media_player_pause (libvlc_media_player_t *p_mi)
' Toggle pause.
Private Extern libvlc_media_player_pause(p_mi As Pointer)

' void libvlc_media_player_release (libvlc_media_player_t * p_mi)
' Release a media_player after use Decrement the reference count of a media player object.
Private Extern libvlc_media_player_release(p_mi As Pointer)

' void libvlc_media_release (libvlc_media_t *p_md)
' Decrement the reference count of a media descriptor object.
Private Extern libvlc_media_release(p_md As Pointer)

' libvlc_release (libvlc_instance_t * p_instance)
' Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.
Private Extern libvlc_release(p_instance As Pointer)


Public Sub Button1_Click()

 Dim ss As String[]
 Dim m As Pointer
 Dim id As Integer
  
 ss = ["--audio-visual=visual", "--effect-list=spectrum"]
  
' Inizializza la libreria VLC:
 inst = libvlc_new(ss.Count, ss)
   
' Crea un nuovo oggetto multimedia:
 m = libvlc_media_new_path(inst, "/percorso/del/file/audio")
   
' Crea un media player:
 mp = libvlc_media_player_new_from_media(m)
   
' Chiude il descrittore dell'oggetto media:
 libvlc_media_release(m)
  
' Per far mostrare l'effetto video "Analizzatore di spettro" nella "DrawingArea", ricaviamo il suo identificativo:
 id = DrawingArea1.Id
  
' Passiamo l'identificativo della finestra, nella quale dovrà essere mostrato l'effetto "Spectrum analyzer":
 libvlc_media_player_set_xwindow(mp, id)
   
 ' Avvia l'esecuzione del file audio da parte del media player:
 libvlc_media_player_play(mp)

 Repeat
   TextLabel1.Text = "Durata: " & Str(Time(0, 0, 0, libvlc_media_player_get_length(mp, 0)))
   TextLabel2.Text = "<FONT Color=red>" & Str(Time(0, 0, 0, libvlc_media_player_get_time(mp)))
   Wait 0.01
 Until libvlc_media_player_get_state(mp) > libvlc_Paused

' Rilascia e chiude il media player:
 libvlc_media_player_release(mp)
 
' Chiude la libreria VLC:
 libvlc_release(inst)

End


Public Sub Button2_Click()

' Arresta l'esecuzione del file audio:
 libvlc_media_player_stop(mp)

End


Public Sub ToggleButton1_Click()

' Pone in pausa o riprende (se già in pausa) l'esecuzione del file audio:
 libvlc_media_player_pause(mp)

End

Quest'altro esempio è più completo e complesso del precedente. La particolarità del codice seguente è che è possibile selezionare nel codice fino a 5 effetti grafici VLC.

Private bt1 As Button
Private bt2 As Button
Private tb As ToggleButton
Private tl0 As TextLabel
Private tl1 As TextLabel
Private tl2 As TextLabel
Private menu As Menu
Private fileaudio As String
Private inst As Pointer
Private m As Pointer
Private mp As Pointer


Library "libvlc:5.6.1"

Private Enum libvlc_NothingSpecial = 0, libvlc_Opening, libvlc_Buffering, libvlc_Playing,
             libvlc_Paused, libvlc_Stopped, libvlc_Ended, libvlc_Error

' libvlc_instance_t * libvlc_new (int argc, const char *const *argv)
' Create And initialize a libvlc instance.
Private Extern libvlc_new(argc As Integer, argv As String[]) As Pointer

' libvlc_media_t * libvlc_media_new_path (libvlc_instance_t *p_instance, const char *path)
' Create a media for a certain file path.
Private Extern libvlc_media_new_path(p_instance As Pointer, path As String) As Pointer

' libvlc_media_player_t * libvlc_media_player_new_from_media (libvlc_media_t *p_md)
' Create a Media Player object from a Media.
Private Extern libvlc_media_player_new_from_media(p_md As Pointer) As Pointer

' void libvlc_media_player_set_xwindow (libvlc_media_player_t *p_mi, uint32_t drawable)
' Set an X Window System drawable where the media player should render its video output.
Private Extern libvlc_media_player_set_xwindow(p_mi As Pointer, drawable As Integer)

' int libvlc_media_player_play (libvlc_media_player_t * p_mi)
' Play the video file.
Private Extern libvlc_media_player_play(p_mi As Pointer) As Integer

' void libvlc_media_player_stop (libvlc_media_player_t * p_mi)
' Stop the video file.
Private Extern libvlc_media_player_stop(p_mi As Pointer)

' libvlc_time_t libvlc_media_player_get_length(libvlc_media_player_t *, libvlc_exception_t *)
' Get the current movie length (in ms).
Private Extern libvlc_media_player_get_length(p_mi As Pointer, l_ex As Pointer) As Long

' libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)
' Get the current movie time (in ms).
Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Long

' libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)
' Get current movie state.
Private Extern libvlc_media_player_get_state(p_mi As Pointer) As Integer

' void libvlc_media_player_pause (libvlc_media_player_t *p_mi)
' Toggle pause.
Private Extern libvlc_media_player_pause(p_mi As Pointer)

' void libvlc_media_player_release (libvlc_media_player_t * p_mi)
' Release a media_player after use Decrement the reference count of a media player object.
Private Extern libvlc_media_player_release(p_mi As Pointer)

' void libvlc_media_release (libvlc_media_t *p_md)
' Decrement the reference count of a media descriptor object.
Private Extern libvlc_media_release(p_md As Pointer)

' libvlc_release (libvlc_instance_t * p_instance)
' Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.
Private Extern libvlc_release(p_instance As Pointer)


Public Sub Form_Open()
 
 Dim effetti, ss As String[]
 Dim argc As Integer
 
 GestioneOggetti()
 effetti = ["dummy", "scope", "spectrum", "spectrometer", "vuMeter"]
  
 ss = ["--audio", "--audio-visual=visual", "--effect-list=" & effetti[4], "--visual-80-bands", "--visual-peaks", 
       "--width= 350", "--height=250", "--gain=1.000", "--no-xli"]
  
' Indica quanti, e dunque, quali effetti, compresi nel vettore "ss" si vogliono utilizzare:
 argc = ss.Count
  
' Inizializza la libreria VLC:
 inst = libvlc_new(argc, ss)
  
End


Public Sub Button1_Click()
 
 Dim id As Integer
 Dim DrAr As DrawingArea
  
 With DrAr = New DrawingArea(Me)
   .X = 10
   .Y = 10
   .W = 350
   .H = 250
 End With
  
 bt1.Enabled = False
 tb.Enabled = True
 tb.Value = False
   
' Crea un nuovo oggetto multimedia.
' Nel secondo argomento della funzione va specificato il percorso del file audio.
 m = libvlc_media_new_path(inst, fileaudio)
  
' Crea un media player:
 mp = libvlc_media_player_new_from_media(m)
 
' Chiude l'oggetto media:
 libvlc_media_release(m)
  
' Per far mostrare l'effetto VLC nella "DrawingArea", ricaviamo il suo identificativo:
 id = DrAr.Id
  
' Passiamo l'identificativo della finestra, nella quale dovrà essere mostrato l'effetto VLC:
 libvlc_media_player_set_xwindow(mp, id)
  
' Avvia l'esecuzione del file audio da parte del media player:
 libvlc_media_player_play(mp)
  
 Repeat
   tl1.Text = "Durata: " & Str(Time(0, 0, 0, libvlc_media_player_get_length(mp, 0)))
   tl2.Text = "<FONT Color=red>" & Str(Time(0, 0, 0, libvlc_media_player_get_time(mp)))
   Wait 0.01
 Until libvlc_media_player_get_state(mp) > libvlc_Paused
  
 mp = 0
 bt1.Enabled = True
  
End


Public Sub Button2_Click()
 
 Stop()
 
End


Public Sub ToggleButton1_Click()
 
' Pone in pausa o riprende (se già in pausa) l'esecuzione del file audio:
 libvlc_media_player_pause(mp)
  
End


Public Sub Form_Close()
 
 If Object.IsValid(Me) Then Chiude()

End


Public Sub Menu_Click()

 Select Case Last.Name
   Case "Apri"
     With Dialog
       .Title = "Apre file..."
       .Filter = ["*.mp3; *.ogg; *.wav; *.wma", "File audio"]
       If .OpenFile() Then Return
       fileaudio = .Path
     End With
     If mp > 0 Then Stop()
     tl0.Text = File.Name(fileaudio)
     tl1.Text = Null
     tl2.Text = Null
     bt1.Enabled = True
   Case "Esci"
     Chiude()
 End Select

End


Private Procedure Chiude()
 
 If mp > 0 Then
' Arresta l'esecuzione del file audio:
   libvlc_media_player_stop(mp)
' Rilascia e chiude il media player:
   libvlc_media_player_release(mp)
 Endif
 
' Chiude la libreria VLC:
 libvlc_release(inst)
 
 If Object.IsValid(Me) Then
   Object.Lock(Me)
   Me.Close
 Endif
  
End


Private Procedure Stop()
 
 If mp > 0 Then
' Arresta l'esecuzione del file video:
   libvlc_media_player_stop(mp)
' Rilascia e chiude il media player:
   libvlc_media_player_release(mp)
 Endif
 
 tb.Enabled = False
 tb.Value = False
  
End


Private Procedure GestioneOggetti()
 
 Dim mn1, mn2 As Menu
 
 With Me
   .W = 400
   .H = 370
 End With
 With tl0 = New TextLabel(Me)
   .X = 10
   .Y = 265
   .W = 350
   .H = 20
 End With
 With tl1 = New TextLabel(Me)
   .X = 10
   .Y = tl0.Y + tl0.H
   .W = 120
   .H = 18
   .Alignment = Align.Top
 End With
 With tl2 = New TextLabel(Me)
   .X = tl1.X + tl1.W + 30
   .Y = tl0.Y + tl0.H
   .W = 120
   .H = 18
   .Alignment = Align.TopLeft
 End With
 With bt1 = New Button(Me) As "Button1"
   .X = 10
   .Y = 300
   .W = 300
   .H = 40
   .Foreground = Color.DarkGreen
   .Text = "Esegui"
   .Enabled = False
 End With
 With bt2 = New Button(Me) As "Button2"
   .X = bt1.X + bt1.W + 20
   .Y = 300
   .W = 50
   .H = 40
   .Foreground = Color.DarkRed
   .Text = "Stop"
 End With
 With tb = New ToggleButton(Me) As "ToggleButton1"
   .X = bt2.X
   .Y = 220
   .W = 50
   .H = 40
   .Text = "Pausa"
   .Enabled = False
 End With
 With menu = New Menu(Me) As "Menu"
   .Caption = "File"
 End With
 With mn1 = New Menu(menu, False) As "Menu"
   .Caption = "Apri file..."
   .Name = "Apri"
 End With
 With mn2 = New Menu(menu, False) As "Menu"
   .Caption = "Esci"
   .Name = "Esci"
 End With
  
End

Esempio con applicazione a riga di comando

Library "libvlc:5.6.1"

Private Enum libvlc_NothingSpecial = 0,
             libvlc_Opening,
             libvlc_Buffering,
             libvlc_Playing,
             libvlc_Paused,
             libvlc_Stopped,
             libvlc_Ended,
             libvlc_Error

' libvlc_instance_t * libvlc_new (int argc, const char *const *argv)
' Create And initialize a libvlc instance.
Private Extern libvlc_new(argc As Integer, argv As String[]) As Pointer

' libvlc_media_t * libvlc_media_new_path (libvlc_instance_t *p_instance, const char *path)
' Create a media for a certain file path.
Private Extern libvlc_media_new_path(p_instance As Pointer, path As String) As Pointer

' libvlc_media_player_t * libvlc_media_player_new_from_media (libvlc_media_t *p_md)
' Create a Media Player object from a Media.
Private Extern libvlc_media_player_new_from_media(p_md As Pointer) As Pointer

' int libvlc_media_player_play (libvlc_media_player_t * p_mi)
' Play the audio file.
Private Extern libvlc_media_player_play(p_mi As Pointer) As Integer
 
' libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)
' Get the current movie time (in ms).
Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Long

' libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)
' Get current movie state.
Private Extern libvlc_media_player_get_state(p_mi As Pointer) As Long
 
' void libvlc_media_player_release (libvlc_media_player_t * p_mi)
' Release a media_player after use Decrement the reference count of a media player object.
Private Extern libvlc_media_player_release(p_mi As Pointer)

' void libvlc_media_release (libvlc_media_t *p_md)
' Decrement the reference count of a media descriptor object.
Private Extern libvlc_media_release(p_md As Pointer)

' libvlc_release (libvlc_instance_t * p_instance)
' Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.
Private Extern libvlc_release(p_instance As Pointer)


Public Sub Main()

 Dim inst, m, mp As Pointer
      
' Inizializza la libreria VLC:
 inst = libvlc_new(0, Null)
   
' Crea un nuovo oggetto multimedia:
 m = libvlc_media_new_path(inst, "/percorso/del/file/audio")
   
' Crea un media player:
 mp = libvlc_media_player_new_from_media(m)
 
 libvlc_media_release(m)
 
 ' Avvia l'esecuzione del file audio da parte del media player:
 libvlc_media_player_play(mp)

 While libvlc_media_player_get_state(mp) < libvlc_Stopped
   Write "\r" & Str(Time(0, 0, 0, libvlc_media_player_get_time(mp)))
   Flush
   White 0.01
 Wend

' Va in chiusura:
 libvlc_media_player_release(mp)
 libvlc_release(inst)

End



Riferimenti