Differenze tra le versioni di "Riproduzione dell'audio di radio WEB con le funzioni esterne del API di GStreamer"
Da Gambas-it.org - Wikipedia.
(Creata pagina con 'Le stazioni radio via WEB possono essere ascoltate utilizzando le risorse del API di GStreamer. Un possibile semplice codice è il seguente: Private Const GST_STATE_NULL As...') |
|||
(15 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 2: | Riga 2: | ||
− | + | ==Uso del plug-in ''playbin''== | |
− | |||
− | |||
− | |||
Private play As Pointer | Private play As Pointer | ||
Library "libgstreamer-1.0" | Library "libgstreamer-1.0" | ||
− | <FONT color=gray>' ''gst_init (&argc, &argv)''</font> | + | Private Const GST_STATE_NULL As Integer = 1 |
+ | Private Const GST_STATE_PLAYING As Integer = 4 | ||
+ | |||
+ | <FONT color=gray>' ''gst_init (&argc, &argv)'' | ||
+ | ' ''Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.''</font> | ||
Private Extern gst_init(argc As Integer, argv As Pointer) | Private Extern gst_init(argc As Integer, argv As Pointer) | ||
− | <FONT color=gray>' ''GstElement * gst_element_factory_make(const gchar *factoryname, Const gchar * name)''</font> | + | <FONT color=gray>' ''GstElement * gst_element_factory_make(const gchar *factoryname, Const gchar * name)'' |
+ | ' ''Create a new element of the type defined by the given element factory.''</font> | ||
Private Extern gst_element_factory_make(factoryname As String, name As String) As Pointer | Private Extern gst_element_factory_make(factoryname As String, name As String) As Pointer | ||
− | <FONT color=gray>' ''void g_object_set(gpointer object, const gchar *first_property_name, ...)''</font> | + | <FONT color=gray>' ''void g_object_set(gpointer object, const gchar *first_property_name, ...)'' |
+ | ' ''Sets properties on an object.''</font> | ||
Private Extern g_object_set(gobject As Pointer, key As String, value As String, nl As String) | Private Extern g_object_set(gobject As Pointer, key As String, value As String, nl As String) | ||
− | <FONT color=gray>' ''GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)''</font> | + | <FONT color=gray>' ''GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)'' |
+ | ' ''Sets the state of the element.''</font> | ||
Private Extern gst_element_set_state(gstobject As Pointer, state As Integer) As Integer | Private Extern gst_element_set_state(gstobject As Pointer, state As Integer) As Integer | ||
− | <FONT color=gray>' ''void gst_object_unref(gpointer object)''</font> | + | <FONT color=gray>' ''void gst_object_unref(gpointer object)'' |
+ | ' ''Decrements the reference count on object .''</font> | ||
Private Extern gst_object_unref(gobject As Pointer) | Private Extern gst_object_unref(gobject As Pointer) | ||
− | + | Public Sub Form_Open() | |
− | + | Dim retI As Integer | |
gst_init(0, 0) | gst_init(0, 0) | ||
Riga 34: | Riga 39: | ||
play = gst_element_factory_make("playbin", "play") | play = gst_element_factory_make("playbin", "play") | ||
− | <FONT color=gray>' ''Nel terzo argomento della seguente funzione va inserito | + | <FONT color=gray>' ''Nel terzo argomento della seguente funzione va inserito l'indirizzo web del flusso di dati audio in tempo reale:''</font> |
− | + | g_object_set(play, "uri", "https://funkyradio.streamingmedia.it/audio.aac", Null) | |
− | g_object_set(play, "uri", " | ||
− | <FONT color=gray>' '' | + | <FONT color=gray>' ''Avvia la riproduzione audio della radio-web:''</font> |
retI = gst_element_set_state(play, GST_STATE_PLAYING) | retI = gst_element_set_state(play, GST_STATE_PLAYING) | ||
Print "Stato di cambiamento = "; retI | Print "Stato di cambiamento = "; retI | ||
− | + | End | |
− | + | Public Sub Button1_Click() | |
− | + | Dim retI As Integer | |
− | <FONT color=gray>' '' | + | <FONT color=gray>' ''Arresta la riproduzione audio:''</font> |
retI = gst_element_set_state(play, GST_STATE_NULL) | retI = gst_element_set_state(play, GST_STATE_NULL) | ||
Print "Stato di cambiamento = "; retI | Print "Stato di cambiamento = "; retI | ||
Riga 55: | Riga 59: | ||
gst_object_unref(play) | gst_object_unref(play) | ||
− | '''End''' | + | End |
+ | |||
+ | |||
+ | ==Uso della funzione ''gst_parse_launch( )'' e il plugin "''uridecodebin''"== | ||
+ | Nell'esempio, che segue, sarà sufficiente premere il tasto "Invio" per chiudere il programma. | ||
+ | Private bo As Boolean | ||
+ | |||
+ | |||
+ | Library "libgstreamer-1.0" | ||
+ | |||
+ | Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING | ||
+ | Private Const GST_FORMAT_TIME As Integer = 3 | ||
+ | |||
+ | <FONT color=gray>' ''gst_init (int *argc, char **argv[])'' | ||
+ | ' ''Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.''</font> | ||
+ | Private Extern gst_init(argc As Pointer, argv As Pointer) | ||
+ | |||
+ | <FONT color=gray>' ''GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error) | ||
+ | ' ''Create a new pipeline based on command line syntax.''</font> | ||
+ | Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer | ||
+ | |||
+ | <FONT color=gray>' ''GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state) | ||
+ | ' ''Sets the state of the element.''</font> | ||
+ | Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer | ||
+ | |||
+ | <FONT color=gray>' ''gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur) | ||
+ | ' ''Queries an element for the stream position in nanoseconds.''</font> | ||
+ | Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean | ||
+ | |||
+ | <FONT color=gray>' ''void gst_object_unref(gpointer object) | ||
+ | ' ''Decrements the reference count on object.''</font> | ||
+ | Private Extern gst_object_unref(gobject As Pointer) | ||
+ | |||
+ | |||
+ | Public Sub Main() | ||
+ | |||
+ | Dim audio As Pointer | ||
+ | Dim pos As Long | ||
+ | |||
+ | gst_init(0, 0) | ||
+ | |||
+ | audio = gst_parse_launch("uridecodebin uri=<FONT color=darkgreen>''http://indirizzo/del/flusso/della/radio/web/live''</font> ! audioconvert ! autoaudiosink", 0) | ||
+ | |||
+ | <FONT color=gray>' ''Avvia l'esecuzione audio della radio web:''</font> | ||
+ | gst_element_set_state(audio, GST_STATE_PLAYING) | ||
+ | |||
+ | Repeat | ||
+ | gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos)) | ||
+ | Write "\rTempo trascorso: " & Str(Time(0, 0, 0, pos / 1000000)) | ||
+ | Wait 0.01 | ||
+ | Until bo = True | ||
+ | |||
+ | gst_object_unref(audio) | ||
+ | |||
+ | Quit | ||
+ | |||
+ | End | ||
+ | |||
+ | |||
+ | Public Sub Application_Read() <FONT color=gray>' ''Premendo il tasto "Invio", si chiuderà il programma''</font> | ||
+ | |||
+ | bo = True | ||
+ | |||
+ | End | ||
+ | |||
+ | ===Riproduzione audio e finale registrazione del flusso di una radio-web in un file MP3=== | ||
+ | Private bo As Boolean | ||
+ | |||
+ | |||
+ | Library "libgstreamer-1.0" | ||
+ | |||
+ | Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING | ||
+ | Private Const GST_FORMAT_TIME As Integer = 3 | ||
+ | |||
+ | <FONT color=gray>' ''gst_init (int *argc, char **argv[])'' | ||
+ | ' ''Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.''</font> | ||
+ | Private Extern gst_init(argc As Pointer, argv As Pointer) | ||
+ | |||
+ | <FONT color=gray>' ''GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error) | ||
+ | ' ''Create a new pipeline based on command line syntax.''</font> | ||
+ | Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer | ||
+ | |||
+ | <FONT color=gray>' ''GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state) | ||
+ | ' ''Sets the state of the element.''</font> | ||
+ | Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer | ||
+ | |||
+ | <FONT color=gray>' ''gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur) | ||
+ | ' ''Queries an element for the stream position in nanoseconds.''</font> | ||
+ | Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean | ||
+ | |||
+ | <FONT color=gray>' ''void gst_object_unref(gpointer object) | ||
+ | ' ''Decrements the reference count on object.''</font> | ||
+ | Private Extern gst_object_unref(gobject As Pointer) | ||
+ | |||
+ | |||
+ | Public Sub Main() | ||
+ | |||
+ | Dim audio As Pointer | ||
+ | Dim pos As Long | ||
+ | |||
+ | gst_init(0, 0) | ||
+ | |||
+ | audio = gst_parse_launch("uridecodebin uri=<FONT color=darkgreen>''http://indirizzo/del/flusso/della/radio/web/live''</font> ! audioconvert ! tee name=radio ! queue ! autoaudiosink radio. ! queue ! lamemp3enc target=bitrate bitrate=128 cbr=true ! filesink location=/tmp/output.mp3", 0) | ||
+ | |||
+ | <FONT color=gray>' ''Avvia l'esecuzione audio della radio web:''</font> | ||
+ | gst_element_set_state(audio, GST_STATE_PLAYING) | ||
+ | |||
+ | Repeat | ||
+ | gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos)) | ||
+ | Write "\rTempo trascorso: " & Str(Time(0, 0, 0, pos / 1000000)) | ||
+ | Wait 0.01 | ||
+ | Until bo = True | ||
+ | |||
+ | gst_object_unref(audio) | ||
+ | |||
+ | Quit | ||
+ | |||
+ | End | ||
+ | |||
+ | |||
+ | Public Sub Application_Read() <FONT color=gray>' ''Premendo il tasto "Invio", si chiuderà il programma''</font> | ||
+ | |||
+ | bo = True | ||
+ | |||
+ | End | ||
+ | |||
+ | ==Uso della funzione ''gst_parse_launch( )'' e i plugin "''souphttpsrc''" e "''decodebin''"== | ||
+ | Nell'esempio, che segue, sarà sufficiente premere il tasto "Invio" per chiudere il programma. | ||
+ | Private bo As Boolean | ||
+ | |||
+ | |||
+ | Library "libgstreamer-1.0" | ||
+ | |||
+ | Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING | ||
+ | Private Const GST_FORMAT_TIME As Integer = 3 | ||
+ | |||
+ | <FONT color=gray>' ''gst_init (int *argc, char **argv[])'' | ||
+ | ' ''Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.''</font> | ||
+ | Private Extern gst_init(argc As Pointer, argv As Pointer) | ||
+ | |||
+ | <FONT color=gray>' ''GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error) | ||
+ | ' ''Create a new pipeline based on command line syntax.''</font> | ||
+ | Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer | ||
+ | |||
+ | <FONT color=gray>' ''GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state) | ||
+ | ' ''Sets the state of the element.''</font> | ||
+ | Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer | ||
+ | |||
+ | <FONT color=gray>' ''gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur) | ||
+ | ' ''Queries an element for the stream position in nanoseconds.''</font> | ||
+ | Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean | ||
+ | |||
+ | <FONT color=gray>' ''void gst_object_unref(gpointer object) | ||
+ | ' ''Decrements the reference count on object.''</font> | ||
+ | Private Extern gst_object_unref(gobject As Pointer) | ||
+ | |||
+ | |||
+ | Public Sub Main() | ||
+ | |||
+ | Dim audio As Pointer | ||
+ | Dim pos As Long | ||
+ | |||
+ | gst_init(0, 0) | ||
+ | |||
+ | audio = gst_parse_launch("souphttpsrc location=<FONT color=darkgreen>''http://indirizzo/del/flusso/della/radio/web/live''</font> ! decodebin ! audioconvert ! autoaudiosink", 0) | ||
+ | |||
+ | <FONT color=gray>' ''Avvia l'esecuzione audio della radio web:''</font> | ||
+ | gst_element_set_state(audio, GST_STATE_PLAYING) | ||
+ | |||
+ | Repeat | ||
+ | gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos)) | ||
+ | Write "\rTempo trascorso: " & Str(Time(0, 0, 0, pos / 1000000)) | ||
+ | Wait 0.01 | ||
+ | Until bo = True | ||
+ | |||
+ | gst_object_unref(audio) | ||
+ | |||
+ | Quit | ||
+ | |||
+ | End | ||
+ | |||
+ | |||
+ | Public Sub Application_Read() <FONT color=gray>' ''Premendo il tasto "Invio", si chiuderà il programma''</font> | ||
+ | |||
+ | bo = True | ||
+ | |||
+ | End | ||
+ | |||
+ | |||
+ | |||
+ | ==Uso della funzione ''gst_parse_launch( )'' e del plugin ''jackaudiosink''== | ||
+ | Per l'esecuzione del seguente codice è necessario avviare preliminarmente il programma ''Jack''. | ||
+ | <BR>Sarà sufficiente premere il tasto "Invio" per chiudere il programma. | ||
+ | Private bo As Boolean | ||
+ | |||
+ | |||
+ | Library "libgstreamer-1.0" | ||
+ | |||
+ | Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING | ||
+ | Private Const GST_FORMAT_TIME As Integer = 3 | ||
+ | |||
+ | <FONT color=gray>' ''gst_init (int *argc, char **argv[])'' | ||
+ | ' ''Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.''</font> | ||
+ | Private Extern gst_init(argc As Pointer, argv As Pointer) | ||
+ | |||
+ | <FONT color=gray>' ''GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error) | ||
+ | ' ''Create a new pipeline based on command line syntax.''</font> | ||
+ | Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer | ||
+ | |||
+ | <FONT color=gray>' ''GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state) | ||
+ | ' ''Sets the state of the element.''</font> | ||
+ | Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer | ||
+ | |||
+ | <FONT color=gray>' ''gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur) | ||
+ | ' ''Queries an element for the stream position in nanoseconds.''</font> | ||
+ | Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean | ||
+ | |||
+ | <FONT color=gray>' ''void gst_object_unref(gpointer object) | ||
+ | ' ''Decrements the reference count on object.''</font> | ||
+ | Private Extern gst_object_unref(gobject As Pointer) | ||
+ | |||
+ | |||
+ | Public Sub Main() | ||
+ | |||
+ | Dim audio As Pointer | ||
+ | Dim pos As Long | ||
+ | |||
+ | gst_init(0, 0) | ||
+ | |||
+ | audio = gst_parse_launch("uridecodebin uri=http://maxxima.mine.nu:8080/maxxima.mp3 ! audioconvert ! audioresample ! <FONT color=#B22222>jackaudiosink</font>", 0) | ||
+ | |||
+ | <FONT color=gray>' ''Avvia l'esecuzione audio della radio web:''</font> | ||
+ | gst_element_set_state(audio, GST_STATE_PLAYING) | ||
+ | |||
+ | Repeat | ||
+ | gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos)) | ||
+ | Write "\rTempo trascorso: " & Str(Time(0, 0, 0, pos / 1000000)) | ||
+ | Wait 0.01 | ||
+ | Until bo = True | ||
+ | |||
+ | gst_object_unref(audio) | ||
+ | |||
+ | Quit | ||
+ | |||
+ | End | ||
+ | |||
+ | |||
+ | Public Sub Application_Read() <FONT color=gray>' ''Premendo il tasto "Invio", si chiuderà il programma''</font> | ||
+ | |||
+ | bo = True | ||
+ | |||
+ | End |
Versione attuale delle 09:40, 16 gen 2024
Le stazioni radio via WEB possono essere ascoltate utilizzando le risorse del API di GStreamer.
Indice
Uso del plug-in playbin
Private play As Pointer Library "libgstreamer-1.0" Private Const GST_STATE_NULL As Integer = 1 Private Const GST_STATE_PLAYING As Integer = 4 ' gst_init (&argc, &argv) ' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins. Private Extern gst_init(argc As Integer, argv As Pointer) ' GstElement * gst_element_factory_make(const gchar *factoryname, Const gchar * name) ' Create a new element of the type defined by the given element factory. Private Extern gst_element_factory_make(factoryname As String, name As String) As Pointer ' void g_object_set(gpointer object, const gchar *first_property_name, ...) ' Sets properties on an object. Private Extern g_object_set(gobject As Pointer, key As String, value As String, nl As String) ' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state) ' Sets the state of the element. Private Extern gst_element_set_state(gstobject As Pointer, state As Integer) As Integer ' void gst_object_unref(gpointer object) ' Decrements the reference count on object . Private Extern gst_object_unref(gobject As Pointer) Public Sub Form_Open() Dim retI As Integer gst_init(0, 0) play = gst_element_factory_make("playbin", "play") ' Nel terzo argomento della seguente funzione va inserito l'indirizzo web del flusso di dati audio in tempo reale: g_object_set(play, "uri", "https://funkyradio.streamingmedia.it/audio.aac", Null) ' Avvia la riproduzione audio della radio-web: retI = gst_element_set_state(play, GST_STATE_PLAYING) Print "Stato di cambiamento = "; retI End Public Sub Button1_Click() Dim retI As Integer ' Arresta la riproduzione audio: retI = gst_element_set_state(play, GST_STATE_NULL) Print "Stato di cambiamento = "; retI gst_object_unref(play) End
Uso della funzione gst_parse_launch( ) e il plugin "uridecodebin"
Nell'esempio, che segue, sarà sufficiente premere il tasto "Invio" per chiudere il programma.
Private bo As Boolean Library "libgstreamer-1.0" Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING Private Const GST_FORMAT_TIME As Integer = 3 ' gst_init (int *argc, char **argv[]) ' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins. Private Extern gst_init(argc As Pointer, argv As Pointer) ' GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error) ' Create a new pipeline based on command line syntax. Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer ' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state) ' Sets the state of the element. Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer ' gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur) ' Queries an element for the stream position in nanoseconds. Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean ' void gst_object_unref(gpointer object) ' Decrements the reference count on object. Private Extern gst_object_unref(gobject As Pointer) Public Sub Main() Dim audio As Pointer Dim pos As Long gst_init(0, 0) audio = gst_parse_launch("uridecodebin uri=http://indirizzo/del/flusso/della/radio/web/live ! audioconvert ! autoaudiosink", 0) ' Avvia l'esecuzione audio della radio web: gst_element_set_state(audio, GST_STATE_PLAYING) Repeat gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos)) Write "\rTempo trascorso: " & Str(Time(0, 0, 0, pos / 1000000)) Wait 0.01 Until bo = True gst_object_unref(audio) Quit End Public Sub Application_Read() ' Premendo il tasto "Invio", si chiuderà il programma bo = True End
Riproduzione audio e finale registrazione del flusso di una radio-web in un file MP3
Private bo As Boolean Library "libgstreamer-1.0" Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING Private Const GST_FORMAT_TIME As Integer = 3 ' gst_init (int *argc, char **argv[]) ' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins. Private Extern gst_init(argc As Pointer, argv As Pointer) ' GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error) ' Create a new pipeline based on command line syntax. Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer ' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state) ' Sets the state of the element. Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer ' gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur) ' Queries an element for the stream position in nanoseconds. Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean ' void gst_object_unref(gpointer object) ' Decrements the reference count on object. Private Extern gst_object_unref(gobject As Pointer) Public Sub Main() Dim audio As Pointer Dim pos As Long gst_init(0, 0) audio = gst_parse_launch("uridecodebin uri=http://indirizzo/del/flusso/della/radio/web/live ! audioconvert ! tee name=radio ! queue ! autoaudiosink radio. ! queue ! lamemp3enc target=bitrate bitrate=128 cbr=true ! filesink location=/tmp/output.mp3", 0) ' Avvia l'esecuzione audio della radio web: gst_element_set_state(audio, GST_STATE_PLAYING) Repeat gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos)) Write "\rTempo trascorso: " & Str(Time(0, 0, 0, pos / 1000000)) Wait 0.01 Until bo = True gst_object_unref(audio) Quit End Public Sub Application_Read() ' Premendo il tasto "Invio", si chiuderà il programma bo = True End
Uso della funzione gst_parse_launch( ) e i plugin "souphttpsrc" e "decodebin"
Nell'esempio, che segue, sarà sufficiente premere il tasto "Invio" per chiudere il programma.
Private bo As Boolean Library "libgstreamer-1.0" Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING Private Const GST_FORMAT_TIME As Integer = 3 ' gst_init (int *argc, char **argv[]) ' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins. Private Extern gst_init(argc As Pointer, argv As Pointer) ' GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error) ' Create a new pipeline based on command line syntax. Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer ' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state) ' Sets the state of the element. Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer ' gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur) ' Queries an element for the stream position in nanoseconds. Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean ' void gst_object_unref(gpointer object) ' Decrements the reference count on object. Private Extern gst_object_unref(gobject As Pointer) Public Sub Main() Dim audio As Pointer Dim pos As Long gst_init(0, 0) audio = gst_parse_launch("souphttpsrc location=http://indirizzo/del/flusso/della/radio/web/live ! decodebin ! audioconvert ! autoaudiosink", 0) ' Avvia l'esecuzione audio della radio web: gst_element_set_state(audio, GST_STATE_PLAYING) Repeat gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos)) Write "\rTempo trascorso: " & Str(Time(0, 0, 0, pos / 1000000)) Wait 0.01 Until bo = True gst_object_unref(audio) Quit End Public Sub Application_Read() ' Premendo il tasto "Invio", si chiuderà il programma bo = True End
Uso della funzione gst_parse_launch( ) e del plugin jackaudiosink
Per l'esecuzione del seguente codice è necessario avviare preliminarmente il programma Jack.
Sarà sufficiente premere il tasto "Invio" per chiudere il programma.
Private bo As Boolean Library "libgstreamer-1.0" Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING Private Const GST_FORMAT_TIME As Integer = 3 ' gst_init (int *argc, char **argv[]) ' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins. Private Extern gst_init(argc As Pointer, argv As Pointer) ' GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error) ' Create a new pipeline based on command line syntax. Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer ' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state) ' Sets the state of the element. Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer ' gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur) ' Queries an element for the stream position in nanoseconds. Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean ' void gst_object_unref(gpointer object) ' Decrements the reference count on object. Private Extern gst_object_unref(gobject As Pointer) Public Sub Main() Dim audio As Pointer Dim pos As Long gst_init(0, 0) audio = gst_parse_launch("uridecodebin uri=http://maxxima.mine.nu:8080/maxxima.mp3 ! audioconvert ! audioresample ! jackaudiosink", 0) ' Avvia l'esecuzione audio della radio web: gst_element_set_state(audio, GST_STATE_PLAYING) Repeat gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos)) Write "\rTempo trascorso: " & Str(Time(0, 0, 0, pos / 1000000)) Wait 0.01 Until bo = True gst_object_unref(audio) Quit End Public Sub Application_Read() ' Premendo il tasto "Invio", si chiuderà il programma bo = True End