|
|
(Una versione intermedia di uno stesso utente non è mostrata) |
Riga 1: |
Riga 1: |
− | '''''Canberra''''' è una libreria che mette a disposizione funzioni e risorse utilizzate principalmente per l'esecuzione di suoni nel caso vengano sollevati ''eventi'' (click, avvio di programma, chiusura di finestre ed applicazioni, etc). Per questa ragione è progettata per eseguire file non eccessivamente grandi, aventi dimensioni <SPAN Style="text-decoration:underline">non superiori</span> a circa 65 Mbyte.
| + | #REDIRECT [[La_gestione_dei_file_audio_mediante_le_funzioni_esterne_del_API_di_Canberra]] |
− | <BR>Un suono-evento viene attivato tramite ''libcanberra'' chiamando la funzione ''ca_context_play ()'' su un oggetto ''ca_context'' creato in precedenza.
| |
− | | |
− | I formati di file audio supportati sono soltanto: .wav e .ogg .
| |
− | | |
− | Per utilizzare le risorse di ''Canberra'' nella propria applicazione Gambas, si dovrà richiamare la libreria dinamica condivisa: "''libcanberra.so.0.2.5''."
| |
− | | |
− | | |
− | Mostriamo di seguito un semplice codice in ambiente grafico:
| |
− | Private ca As Pointer
| |
− |
| |
− |
| |
− | Library "libcanberra:0.2.5"
| |
− |
| |
− | Private Const CA_PROP_MEDIA_FILENAME As String = "media.filename"
| |
− |
| |
− | <FONT color=gray>' ''int ca_context_create (ca_context **c)''
| |
− | ' ''Create an (unconnected) context object.''</font>
| |
− | Private Extern ca_context_create(c As Pointer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''const char * ca_strerror (int code)''
| |
− | ' ''Converts a numerical error code as returned by most libcanberra API functions into a human readable error string.''</font>
| |
− | Private Extern ca_strerror(code As Integer) As String
| |
− |
| |
− | <FONT color=gray>' ''int ca_context_set_driver (ca_context *c, const char *driver)''
| |
− | ' ''Specify the backend driver used. "driver": the backend driver to use (e.g."alsa", "pulse", "null", ...)''</font>
| |
− | Private Extern ca_context_set_driver(c As Pointer, driver As String) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int ca_context_open (ca_context *c)''
| |
− | ' ''Connect the context to the sound system.''</font>
| |
− | Private Extern ca_context_open(c As Pointer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int ca_context_play (ca_context *c, uint32_t id, ...)''
| |
− | ' ''Play one event sound''</font>
| |
− | Private Extern ca_context_play(c As Pointer, id As Integer, cpmf As String, sfile As String, nl As String) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int ca_context_destroy (ca_context *c)''
| |
− | ' ''Destroy a (connected or unconnected) context object.''</font>
| |
− | Private Extern ca_context_destroy(c As Pointer) As Integer
| |
− |
| |
− |
| |
− | '''Public''' Sub Button1_Click()
| |
− |
| |
− | Dim err As Integer
| |
− | Dim nomefile As String
| |
− |
| |
− | nomefile = "<FONT color=gray>''/percorso/del/file/audio''</font>"
| |
− |
| |
− | err = ca_context_create(VarPtr(ca))
| |
− | If err < 0 Then Error.Raise("Impossibile creare un contesto media: " & ca_strerror(err))
| |
− |
| |
− | ca_context_set_driver(ca, "alsa")
| |
− | If err < 0 Then Error.Raise("Impossibile impostare il driver audio da utilizzare: " & ca_strerror(err))
| |
− |
| |
− | err = ca_context_open(ca)
| |
− | If err < 0 Then Error.Raise("Impossibile aprire un contesto media: " & ca_strerror(err))
| |
− |
| |
− | err = ca_context_play(ca, 0, CA_PROP_MEDIA_FILENAME, nomefile, Null)
| |
− | If err < 0 Then Error.Raise("Impossibile eseguire il file audio: " & ca_strerror(err))
| |
− |
| |
− | '''End'''
| |
− |
| |
− |
| |
− | '''Public''' Sub Button2_Click()
| |
− |
| |
− | Dim err As Integer
| |
− |
| |
− | <FONT color=gray>' ''Arresta l'esecuzione del file audio, e cancella il contesto media:''</font>
| |
− | err = ca_context_destroy(ca)
| |
− | If err < 0 Then Error.Raise("Impossibile arrestare il file audio: " & ca_strerror(err))
| |
− |
| |
− | '''End'''
| |
− | | |
− | | |
− | | |
− | | |
− | =Riferimenti=
| |
− | * https://developer.gnome.org/libcanberra/unstable/libcanberra-canberra.html
| |
− | * http://sourcecodebrowser.com/libcanberra/0.3/index.html
| |
− | * http://0pointer.de/lennart/projects/libcanberra
| |
− | * http://libcanberra.sourcearchive.com/documentation/0.15/main.html
| |