|
|
Riga 1: |
Riga 1: |
− | '''LibTagC''' è una libreria per estrarre informazioni generali ed i Tag dei file di vari formati audio.
| + | #REDIRECT [[Estrarre_informazioni_e_TAG_da_file_audio_con_le_funzioni_esterne_del_API_di_Libtag_c]] |
− | | |
− | La documentazione di ''LibTagC'' può essere trovata nel codice sorgente: "''/usr/include/taglib/tag_c.h''" .
| |
− | | |
− | Per poter fruire delle risorse di ''LibTagC'' è necessario utilizzare nelle applicazioni Gambas la libreria: ''libtag_c.so.0.0.0''
| |
− | | |
− | Riportiamo di seguito un semplice esempio, con il quale è possibile estrarre i TAG ed informazioni generali da un file ''mp3'':
| |
− | Library "libtag_c:0.0.0"
| |
− |
| |
− | Private Enum TagLib_File_MPEG = 0,
| |
− | TagLib_File_OggVorbis,
| |
− | TagLib_File_FLAC,
| |
− | TagLib_File_MPC,
| |
− | TagLib_File_OggFlac,
| |
− | TagLib_File_WavPack,
| |
− | TagLib_File_Speex,
| |
− | TagLib_File_TrueAudio,
| |
− | TagLib_File_MP4,
| |
− | TagLib_File_ASF
| |
− |
| |
− | <FONT color=gray>' ''void taglib_set_strings_unicode(BOOL unicode)''
| |
− | ' ''By default all strings coming into or out of TagLib's C API are in UTF8.''
| |
− | ' ''However, it may be desirable For TagLib To operate On Latin1(ISO - 8859 - 1) strings In which Case this should be set To FALSE.''</font>
| |
− | Private Extern taglib_set_strings_unicode(unicode As Boolean)
| |
− |
| |
− | <FONT color=gray>' ''TagLib_File *taglib_file_new_type(const char *filename, TagLib_File_Type type)''
| |
− | ' ''Creates a TagLib file based on \a filename.''</font>
| |
− | Private Extern taglib_file_new(filename As String, type As Integer) As Pointer
| |
− |
| |
− | <FONT color=gray>' ''TagLib_Tag *taglib_file_tag(const TagLib_File *file)''
| |
− | ' ''Returns a pointer to the tag associated with this file.''</font>
| |
− | Private Extern taglib_file_tag(Tl_file As Pointer) As Pointer
| |
− |
| |
− | <FONT color=gray>' ''const TagLib_AudioProperties *taglib_file_audioproperties(const TagLib_File *file)''
| |
− | ' ''Returns a pointer to the the audio properties associated with this file.''</font>
| |
− | Private Extern taglib_file_audioproperties(Tl_file As Pointer) As Pointer
| |
− |
| |
− | <FONT color=gray>' ''char *taglib_tag_title(const TagLib_Tag *tag)''
| |
− | ' ''Returns a string with this tag's title.''</font>
| |
− | Private Extern taglib_tag_title(tag As Pointer) As String
| |
− |
| |
− | <FONT color=gray>' ''char *taglib_tag_artist(const TagLib_Tag *tag)''
| |
− | ' ''Returns a string with this tag's artist.''</font>
| |
− | Private Extern taglib_tag_artist(tag As Pointer) As String
| |
− |
| |
− | <FONT color=gray>' ''char *taglib_tag_album(const TagLib_Tag *tag)''
| |
− | ' ''Returns a string with this tag's album name.''</font>
| |
− | Private Extern taglib_tag_album(tag As Pointer) As String
| |
− |
| |
− | <FONT color=gray>' ''char *taglib_tag_comment(const TagLib_Tag *tag)''
| |
− | ' ''Returns a string with this tag's comment.''</font>
| |
− | Private Extern taglib_tag_comment(tag As Pointer) As String
| |
− |
| |
− | <FONT color=gray>' ''char *taglib_tag_genre(const TagLib_Tag *tag)''
| |
− | ' ''Returns a string with this tag's genre.''</font>
| |
− | Private Extern taglib_tag_genre(tag As Pointer) As String
| |
− |
| |
− | <FONT color=gray>' ''unsigned int taglib_tag_year(const TagLib_Tag *tag)''
| |
− | ' ''Returns the tag's year or 0 if year is not set.''</font>
| |
− | Private Extern taglib_tag_year(tag As Pointer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''unsigned int taglib_tag_track(const TagLib_Tag *tag)''
| |
− | ' ''Returns the tag's track number or 0 if track number is not set.''</font>
| |
− | Private Extern taglib_tag_track(tag As Pointer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int taglib_audioproperties_length(const TagLib_AudioProperties *audioProperties)''
| |
− | ' ''Returns the length of the file in seconds.''</font>
| |
− | Private Extern taglib_audioproperties_length(audioProperties As Pointer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int taglib_audioproperties_bitrate(const TagLib_AudioProperties *audioProperties)''
| |
− | ' ''Returns the bitrate of the file in kb/s.''</font>
| |
− | Private Extern taglib_audioproperties_bitrate(audioProperties As Pointer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int taglib_audioproperties_samplerate(const TagLib_AudioProperties *audioProperties)''
| |
− | ' ''Returns the sample rate of the file in Hz.''</font>
| |
− | Private Extern taglib_audioproperties_samplerate(audioProperties As Pointer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int taglib_audioproperties_channels(const TagLib_AudioProperties *audioProperties)''
| |
− | ' ''Returns the number of channels in the audio stream.''</font>
| |
− | Private Extern taglib_audioproperties_channels(audioProperties As Pointer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''void taglib_tag_free_strings(void)''
| |
− | ' ''Frees all of the strings that have been created by the tag.''</font>
| |
− | Private Extern taglib_tag_free_strings()
| |
− |
| |
− | <FONT color=gray>' ''void taglib_file_free(TagLib_File *file)''
| |
− | ' ''Frees and closes the file.''</font>
| |
− | Private Extern taglib_file_free(Tl_file As Pointer)
| |
− |
| |
− |
| |
− | '''Public''' Sub Main()
| |
− |
| |
− | Dim i, secondi, minuti As Integer
| |
− | Dim TagLib_File, Taglib_tag, TagLib_AudioProperties As Pointer
| |
− | Dim percorsoFile As String
| |
− |
| |
− | taglib_set_strings_unicode(False)
| |
− |
| |
− | percorsoFile = "''/percorso/del/file.mp3''"
| |
− |
| |
− | TagLib_File = taglib_file_new(percorsoFile, TagLib_File_MPEG)
| |
− | If IsNull(TagLib_File) Then Error.Raise("Impossibile caricare il file !")
| |
− |
| |
− | Taglib_tag = taglib_file_tag(TagLib_File)
| |
− | If IsNull(Taglib_tag) Then Error.Raise("Errore alla funzione 'taglib_file_tag()' !")
| |
− |
| |
− | TagLib_AudioProperties = taglib_file_audioproperties(TagLib_File)
| |
− | If IsNull(TagLib_AudioProperties) Then Error.Raise("Errore alla funzione 'taglib_file_audioproperties()' !")
| |
− |
| |
− | <FONT color=gray>' ''Mostra i Tag del file audio:''</font>
| |
− | Print "=== T A G ===\n"
| |
− | Print "Titolo: ", taglib_tag_title(Taglib_tag)
| |
− | Print "Artista: ", taglib_tag_artist(Taglib_tag)
| |
− | Print "Album: ", taglib_tag_album(Taglib_tag)
| |
− | Print "Anno: ", taglib_tag_year(Taglib_tag)
| |
− | Print "Commento: ", taglib_tag_comment(Taglib_tag)
| |
− | Print "Tracce: ", taglib_tag_track(Taglib_tag)
| |
− | Print "Genere: ", taglib_tag_genre(Taglib_tag)
| |
− |
| |
− | <FONT color=gray>' ''Mostra le proprietà del file audio:''</font>
| |
− | Print "\n\n== PROPRIETA' del FILE AUDIO ==\n"
| |
− | Print "Frequenza di campionamento: Hz "; taglib_audioproperties_samplerate(TagLib_AudioProperties)
| |
− | Print "bitrate: "; taglib_audioproperties_bitrate(TagLib_AudioProperties); " kb/s"
| |
− | Print "Canali di uscita: "; taglib_audioproperties_channels(TagLib_AudioProperties)
| |
− | secondi = taglib_audioproperties_length(TagLib_AudioProperties) % 60
| |
− | minuti = (taglib_audioproperties_length(TagLib_AudioProperties) - secondi) / 60
| |
− | Print "Durata: "; minuti; "' "; secondi; Chr(34)
| |
− |
| |
− | <FONT color=gray>' ''Va in chiusura:''</font>
| |
− | taglib_tag_free_strings()
| |
− | taglib_file_free(TagLib_File)
| |
− |
| |
− | '''End'''
| |
− | | |
− | | |
− | | |
− | =Riferimenti=
| |
− | [1] https://taglib.org/ | |