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 mp As Pointer
Library "libvlc:5"
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 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 Integer
' 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)
' 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 m As Pointer
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)
' Per far mostrare l'effetto grafico nella "DrawingArea", ricaviamo il suo identificativo:
id = DrAr.Id
' Passiamo l'identificativo della finestra, nella quale dovrà essere mostrato l'effetto grafico:
libvlc_media_player_set_xwindow(mp, id)
' Avvia l'esecuzione del file audio da parte del media player:
libvlc_media_player_play(mp)
Do
tl1.Text = "Durac.: " & Str(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_length(mp, 0)))
tl2.Text = "<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
mp = 0
bt1.Enabled = True
End
Public Sub Button2_Click()
Stop()
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
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", "*mid", "File Midi"]
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 Stop()
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
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 = "Ejecuta"
.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 = "Abrir file..."
.Name = "Apri"
End With
With mn2 = New Menu(menu, False) As "Menu"
.Caption = "Salir"
.Name = "Esci"
End With
End
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 mp As Pointer
Library "libvlc:5"
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 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 Integer
' 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)
' 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 m As Pointer
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)
' Per far mostrare l'effetto grafico nella "DrawingArea", ricaviamo il suo identificativo:
id = DrAr.Id
' Passiamo l'identificativo della finestra, nella quale dovrà essere mostrato l'effetto grafico:
libvlc_media_player_set_xwindow(mp, id)
' Avvia l'esecuzione del file audio da parte del media player:
libvlc_media_player_play(mp)
Do
tl1.Text = "Durac.: " & Str(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_length(mp, 0)))
tl2.Text = "<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
mp = 0
bt1.Enabled = True
End
Public Sub Button2_Click()
Stop()
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
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", "*mid", "File Midi"]
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 Stop()
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
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 = "Ejecuta"
.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 = "Abrir file..."
.Name = "Apri"
End With
With mn2 = New Menu(menu, False) As "Menu"
.Caption = "Salir"
.Name = "Esci"
End With
End