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

Da Gambas-it.org - Wikipedia.
(Creata pagina con "''Rythmbox'' è una libreria del progetto GNOME capace di gestire ed eseguire diversi formati audio: AAC, MP3, OGG, WAV e WMA. Va utilizzata congiuntamente con alcune funzion...")
 
 
(13 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1: Riga 1:
 
''Rythmbox'' è una libreria del progetto GNOME capace di gestire ed eseguire diversi formati audio: AAC, MP3, OGG, WAV e WMA.
 
''Rythmbox'' è una libreria del progetto GNOME capace di gestire ed eseguire diversi formati audio: AAC, MP3, OGG, WAV e WMA.
  
Va utilizzata congiuntamente con alcune funzioni esterne della libreria di ''GStreamer''. Pertanto sarà necessario avere intallate nel sistema e richiamare in Gambas le librerie dinamiche condivise: "''librhythmbox-core.so.9.0.0''" e "''libgstreamer-1.0.so''"
+
Va utilizzata congiuntamente con alcune funzioni esterne della libreria di ''GStreamer''. Pertanto sarà necessario avere intallate nel sistema e richiamare in Gambas le librerie condivise: "''librhythmbox-core.so.10.0.0'' " e "''libgstreamer-1.0.so'' "
 
 
  
 
Mostriamo un semplice esempio pratico:
 
Mostriamo un semplice esempio pratico:
  Library "librhythmbox-core:9.0.0"
+
  Library "<FONT Color=blue>librhythmbox-core:10.0.0</font>"
 
   
 
   
 
  Private Enum RB_PLAYER_PLAY_REPLACE = 0, RB_PLAYER_PLAY_AFTER_EOS, RB_PLAYER_PLAY_CROSSFADE
 
  Private Enum RB_PLAYER_PLAY_REPLACE = 0, RB_PLAYER_PLAY_AFTER_EOS, RB_PLAYER_PLAY_CROSSFADE
Riga 25: Riga 24:
 
  Private Extern rb_player_get_time(player As Pointer) As Long
 
  Private Extern rb_player_get_time(player As Pointer) As Long
 
   
 
   
 +
<FONT Color=gray>' ''gboolean rb_player_close (RBPlayer *player, const char *uri, GError **error)''
 +
' ''Close the stream corresponding to that URI and free any resources related resources.''</font>
 +
Private Extern rb_player_close(player As Pointer, uri As String, gerror As Pointer) As Boolean
 
   
 
   
  Library "libgstreamer-1.0"
+
 +
  Library "<FONT Color=red>libgstreamer-1.0</font>"
 
   
 
   
 
  <FONT Color=gray>' ''gst_init (int *argc, char **argv[])''
 
  <FONT Color=gray>' ''gst_init (int *argc, char **argv[])''
Riga 37: Riga 40:
 
   
 
   
 
   
 
   
  '''Public''' Sub Main()
+
  Public Sub Main()
 
   
 
   
   Dim pl, err As Pointer
+
   Dim pl As Pointer
 +
  Dim fileaudio As String
 
   Dim bo As Boolean
 
   Dim bo As Boolean
   Dim tm1 As Long
+
   Dim tm As Long
 
+
 
  gst_init(0, 0)
+
  fileaudio = "<FONT Color=darkgreen>''/percorso/del/file/audio''</font>"
 
+
  If Not Exist(fileaudio) Then Error.Raise("ERRORE !")
  pl = rb_player_new(False, 0)
+
  Print "File audio: "; fileaudio
  If pl = 0 Then Error.Raise("ERRORE !")
+
 
 
+
  gst_init(0, 0)
  err = Alloc(SizeOf(gb.Pointer), 1)
+
 
 
+
  pl = rb_player_new(False, 0)
  bo = rb_player_open(pl, g_filename_to_uri("<FONT Color=gray>''/percorso/del/file/audio''</font>", Null, 0), 0, 0, err)
+
  If pl == 0 Then Error.Raise("ERRORE !")
  If Not bo Then Error.Raise("ERRORE !")
+
 
 
+
  bo = rb_player_open(pl, g_filename_to_uri(fileaudio, Null, 0), 0, 0, 0)
  bo = rb_player_play(pl, RB_PLAYER_PLAY_AFTER_EOS, 0, 0)
+
  If Not bo Then  
  If Not bo Then Error.Raise("ERRORE !")
+
    Chiude(pl, fileaudio)
 
+
    Error.Raise("ERRORE !")
  Wait 0.3
+
  Endif
 
+
 
  Repeat
+
  bo = rb_player_play(pl, RB_PLAYER_PLAY_AFTER_EOS, 0, 0)
    tm1 = rb_player_get_time(pl)
+
  If Not bo Then  
    Write "\r" & CStr(Date(0, 0, 0, 0, 0, 0, tm1 / 1000000))
+
    Chiude(pl, fileaudio)
    Wait 0.001
+
    Error.Raise("ERRORE !")
  Until tm1 = rb_player_get_time(pl)
+
  Endif
 
+
 
  Free(err)
+
  Repeat
 
+
    Wait 0.01
  '''End'''
+
  Until rb_player_get_time(pl) > 0
 
+
 
 +
  Repeat
 +
    tm = rb_player_get_time(pl)
 +
    Write "\r\e[0mPosizione:\e[31m  " & Str(Time(0, 0, 0, tm / 1000000))
 +
    Wait 0.01
 +
  Until tm == rb_player_get_time(pl)
 +
 
 +
  Chiude(pl, fileaudio)
 +
 
 +
  End
 +
 +
 +
Private Procedure Chiude(po As Pointer, fa As String)
 +
 +
  rb_player_close(po, g_filename_to_uri(fa, Null, 0), 0)
 +
 
 +
End
  
  

Versione attuale delle 05:25, 18 giu 2024

Rythmbox è una libreria del progetto GNOME capace di gestire ed eseguire diversi formati audio: AAC, MP3, OGG, WAV e WMA.

Va utilizzata congiuntamente con alcune funzioni esterne della libreria di GStreamer. Pertanto sarà necessario avere intallate nel sistema e richiamare in Gambas le librerie condivise: "librhythmbox-core.so.10.0.0 " e "libgstreamer-1.0.so "

Mostriamo un semplice esempio pratico:

Library "librhythmbox-core:10.0.0"

Private Enum RB_PLAYER_PLAY_REPLACE = 0, RB_PLAYER_PLAY_AFTER_EOS, RB_PLAYER_PLAY_CROSSFADE

' RBPlayer * rb_player_new (gboolean want_crossfade, GError **error)
' Creates a new player object.
Private Extern rb_player_new(want_crossfade As Boolean, gerror As Pointer) As Pointer

' gboolean rb_player_open (RBPlayer *player, const char *uri, gpointer stream_data, GDestroyNotify stream_data_destroy, GError **error)
' Prepares a stream for playback.
Private Extern rb_player_open(player As Pointer, uri As String, stream_data As Pointer, stream_data_destroy As Pointer, gerror As Pointer) As Boolean

' gboolean rb_player_play (RBPlayer *player, RBPlayerPlayType play_type, gint64 crossfade, GError **error)
' Starts playback of the most recently opened stream.
Private Extern rb_player_play(player As Pointer, play_type As Integer, crossfade As Long, gerror As Pointer) As Boolean

' gint64 rb_player_get_time (RBPlayer *player)
' Returns the current playback for the current stream in nanoseconds.
Private Extern rb_player_get_time(player As Pointer) As Long

' gboolean rb_player_close (RBPlayer *player, const char *uri, GError **error)
' Close the stream corresponding to that URI and free any resources related resources.
Private Extern rb_player_close(player As Pointer, uri As String, gerror As Pointer) As Boolean


Library "libgstreamer-1.0"

' 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)

' gchar * g_filename_to_uri (const gchar *filename, const gchar *hostname, GError **error)
' Converts an absolute filename to an escaped ASCII-encoded URI.
Private Extern g_filename_to_uri(filename As String, hostname As String, GError As Pointer) As String


Public Sub Main()

 Dim pl As Pointer
 Dim fileaudio As String
 Dim bo As Boolean
 Dim tm As Long
 
 fileaudio = "/percorso/del/file/audio"
 If Not Exist(fileaudio) Then Error.Raise("ERRORE !")
 Print "File audio: "; fileaudio
 
 gst_init(0, 0)
 
 pl = rb_player_new(False, 0)
 If pl == 0 Then Error.Raise("ERRORE !")
 
 bo = rb_player_open(pl, g_filename_to_uri(fileaudio, Null, 0), 0, 0, 0)
 If Not bo Then 
   Chiude(pl, fileaudio)
   Error.Raise("ERRORE !")
 Endif
 
 bo = rb_player_play(pl, RB_PLAYER_PLAY_AFTER_EOS, 0, 0)
 If Not bo Then 
   Chiude(pl, fileaudio)
   Error.Raise("ERRORE !")
 Endif
 
 Repeat
   Wait 0.01
 Until rb_player_get_time(pl) > 0
 
 Repeat
   tm = rb_player_get_time(pl)
   Write "\r\e[0mPosizione:\e[31m  " & Str(Time(0, 0, 0, tm / 1000000))
   Wait 0.01
 Until tm == rb_player_get_time(pl)
 
 Chiude(pl, fileaudio)
 
End


Private Procedure Chiude(po As Pointer, fa As String)

 rb_player_close(po, g_filename_to_uri(fa, Null, 0), 0)
 
End


Riferimenti