Estrarre informazioni da un file MP3 con le funzioni esterne del API di Smpeg
Da Gambas-it.org - Wikipedia.
Versione del 4 giu 2024 alle 05:32 di Vuott (Discussione | contributi)
La libreria di SMPEG consente di gestire file mpeg, come estrarre informazioni di carattere generale relative al file.
Per poter utilizzare le risorse della libreria Smpeg è necessario richiamare nell'applicazione Gambas la libreria condivisa: "libsmpeg2-2.0.so.0.0.0 ".
Mostriamo di seguito un semplice codice per estrarre le informazioni generali di un file audio mp3:
Library "libsmpeg2-2.0:0.0.0" Public Struct SMPEG_Info has_audio As Integer has_video As Integer width As Integer height As Integer current_frame As Integer current_fps As Float audio_string[80] As Byte audio_current_frame As Integer current_offset As Integer total_size As Integer current_time As Float total_time As Float End Struct Private Const audio As Integer = 1 ' SMPEG* SMPEG_new(const char *file, SMPEG_Info* info, int sdl_audio) ' Create a new SMPEG object from an MPEG file. This function returns a new SMPEG object. Private Extern SMPEG_new(file$ As String, infoP As SMPEG_Info, sdl_audio As Integer) As Pointer ' void SMPEG_delete( SMPEG* mpeg ) ' Delete an SMPEG object Private Extern SMPEG_delete(mp As Pointer) Public Sub Main() Dim info As New SMPEG_Info Dim smpeg As Pointer Dim percorsoFile As String percorsoFile = "/percorso/del/file.mp3" smpeg = SMPEG_new(percorsoFile, info, audio) With info If .has_audio = 0 Then Error.Raise("Errore: il file caricato non è un file audio !") Print "File audio: "; File.Name(percorsoFile) Print "Caratteristiche principali: "; .audio_string.ToString() Print "Dimensione del file audio: "; .total_size; " byte" Print "Durata del brano: "; Time(0, 0, 0, .total_time * 1000) End With ' Va in chiusura: SMPEG_delete(smpeg) End