Differenze tra le versioni di "Riproduzione dell'audio di radio WEB con le funzioni esterne del API di GStreamer"
Da Gambas-it.org - Wikipedia.
Riga 31: | Riga 31: | ||
− | + | Public Sub Form_Open() | |
− | + | Dim retI As Integer | |
gst_init(0, 0) | gst_init(0, 0) | ||
Riga 40: | Riga 40: | ||
<FONT color=gray>' ''Nel terzo argomento della seguente funzione va inserito l'indirizzo web del flusso di dati audio in tempo reale:''</font> | <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", " | + | g_object_set(play, "uri", "https://funkyradio.streamingmedia.it/audio.aac", Null) |
<FONT color=gray>' ''Avvia la riproduzione audio della radio-web:''</font> | <FONT color=gray>' ''Avvia la riproduzione audio della radio-web:''</font> | ||
Riga 46: | Riga 46: | ||
Print "Stato di cambiamento = "; retI | Print "Stato di cambiamento = "; retI | ||
− | + | End | |
− | + | Public Sub Button1_Click() | |
− | + | Dim retI As Integer | |
<FONT color=gray>' ''Arresta la riproduzione audio:''</font> | <FONT color=gray>' ''Arresta la riproduzione audio:''</font> | ||
Riga 59: | Riga 59: | ||
gst_object_unref(play) | gst_object_unref(play) | ||
− | + | End | |
Riga 93: | Riga 93: | ||
− | + | Public Sub Main() | |
Dim audio As Pointer | Dim audio As Pointer | ||
Riga 100: | Riga 100: | ||
gst_init(0, 0) | gst_init(0, 0) | ||
− | audio = gst_parse_launch("uridecodebin uri=<FONT color= | + | audio = gst_parse_launch("uridecodebin uri=<FONT color=darkgreen>''http://indirizzo/della/radio/web/live''</font> ! audioconvert ! autoaudiosink", 0) |
<FONT color=gray>' ''Avvia l'esecuzione audio della radio web:''</font> | <FONT color=gray>' ''Avvia l'esecuzione audio della radio web:''</font> | ||
Riga 115: | Riga 115: | ||
Quit | Quit | ||
− | + | End | |
− | + | Public Sub Application_Read() | |
bo = True | bo = True | ||
− | + | End | |
===Uso della funzione ''gst_parse_launch( )'' e i plugin "''souphttpsrc''" e "''decodebin''"=== | ===Uso della funzione ''gst_parse_launch( )'' e i plugin "''souphttpsrc''" e "''decodebin''"=== | ||
Riga 155: | Riga 155: | ||
− | + | Public Sub Main() | |
Dim audio As Pointer | Dim audio As Pointer | ||
Riga 162: | Riga 162: | ||
gst_init(0, 0) | gst_init(0, 0) | ||
− | audio = gst_parse_launch("souphttpsrc location=<FONT color= | + | audio = gst_parse_launch("souphttpsrc location=<FONT color=darkgreen>''http://indirizzo/della/radio/web/live''</font> ! decodebin ! audioconvert ! autoaudiosink", 0) |
<FONT color=gray>' ''Avvia l'esecuzione audio della radio web:''</font> | <FONT color=gray>' ''Avvia l'esecuzione audio della radio web:''</font> | ||
Riga 177: | Riga 177: | ||
Quit | Quit | ||
− | + | End | |
− | + | Public Sub Application_Read() | |
bo = True | bo = True | ||
− | + | End | |
Riga 220: | Riga 220: | ||
− | + | Public Sub Main() | |
Dim audio As Pointer | Dim audio As Pointer | ||
Riga 227: | Riga 227: | ||
gst_init(0, 0) | gst_init(0, 0) | ||
− | audio = gst_parse_launch("uridecodebin uri= | + | 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> | <FONT color=gray>' ''Avvia l'esecuzione audio della radio web:''</font> | ||
Riga 242: | Riga 242: | ||
Quit | Quit | ||
− | + | End | |
− | + | Public Sub Application_Read() | |
bo = True | bo = True | ||
− | + | End |
Versione delle 17:17, 10 nov 2023
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/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() 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/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() 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() bo = True End