I'm calling the PlaySound_xxx() functions in a thread so that the sound playing doesn't block my main program.
The Errors I'm seeing whenever I play a .wav file is:
On Init:
When playing a .wav:Initializing: VLC Sound System...
Loading Sound: "./Sounds/BubbleClick1.wav"
[xxx] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
Loading Sound: "./Sounds/ChimesSound.wav"
[xxx] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
Loading Sound: "./Sounds/Beep_1000Hz_3000Hz_.25s.wav"
[xxx] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
Loading Sound: "./Sounds/Blast_1000Hz_3000Hz_1s.wav"
[xxx] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
Initializing: Sound System Complete.
[xxx] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
Occasionally I get this wad (and more) of errors, but .wav's still play....
My Sound.c[xxx] alsa audio output error: cannot open ALSA device "default": Device or resource busy
[xxx] main audio output error: Audio output failed
[xxx] main audio output error: The audio device "default" could not be used:
Device or resource busy.
[xxx] main audio output error: module not functional
[xxx] main decoder error: failed to create audio output
[xxx] alsa audio output error: cannot open ALSA device "default": Device or resource busy
[xxx] main audio output error: Audio output failed
[xxx] main audio output error: The audio device "default" could not be used:
Code: Select all
#include <stdio.h> #include <stdlib.h> #include <vlc/vlc.h> #include <unistd.h> libvlc_instance_t * VLCInstance; int SoundsCount = 0; char MySounds[TOTAL_NUMBER_OF_SOUNDS][MAX_SOUND_NAME_LEN] = { "Button Click", "Chimes Sound", "Sound Beep", "Sound Blast", "Mode Select" }; struct SoundStructures Sounds[ MAX_SOUND_COUNT ]; int InitSoundSystem( void ) { farprintfDebugInfoHeader( DEBUG ); printf( "Initializing: VLC Sound System...\n"); /* Load the VLC engine */ VLCInstance = libvlc_new (0, NULL); LoadSoundFile( Sound_ButtonClick, Sound_ButtonClick, 250, "./Sounds/BubbleClick1.wav" ); LoadSoundFile( Sound_Chimes, Sound_Chimes, 5000, "./Sounds/ChimesSound.wav" ); LoadSoundFile( Sound_Beep, Sound_Beep, 600, "./Sounds/Beep_1000Hz_3000Hz_.25s.wav" ); LoadSoundFile( Sound_Blast, Sound_Blast, 1500, "./Sounds/Blast_1000Hz_3000Hz_1s.wav" ); farprintfDebugInfoHeader( DEBUG ); printf( "Initializing: Sound System Complete.\r\n"); return 0; } int LoadSoundFile( unsigned char SoundID, unsigned char SoundsCount, unsigned int Length, unsigned char * FileName ) { farprintfDebugInfoHeader( DEBUG ); printf( "Loading Sound: \"%s\"\r\n", FileName ); Sounds[ SoundsCount ].SoundID = SoundID; Sounds[ SoundsCount ].Length = Length; strcpy( Sounds[ SoundsCount ].FileName, FileName ); Sounds[ SoundsCount ].SoundFileObject = libvlc_media_new_path( VLCInstance, Sounds[ SoundsCount ].FileName ); Sounds[ SoundsCount ].MediaPlayerObject = libvlc_media_player_new_from_media( Sounds[ SoundsCount ].SoundFileObject ); libvlc_media_release( Sounds[ SoundsCount ].SoundFileObject ); return 1; } void PlaySound( unsigned int SoundsIndex ) { if( Sounds[ SoundsIndex ].Playing ) return; Sounds[ SoundsIndex ].Playing = TRUE; /* play the media_player */ libvlc_media_player_play( Sounds[ SoundsIndex ].MediaPlayerObject ); usleep( Sounds[ SoundsIndex ].Length * 1000 ); /* Let it play a bit */ /* Stop playing */ libvlc_media_player_stop( Sounds[ SoundsIndex ].MediaPlayerObject ); Sounds[ SoundsIndex ].Playing = FALSE; /* Free the media_player */ // libvlc_media_player_release (mp); // libvlc_release (inst); } void * PlaySound_ButtonClick( void * peram ) { PlaySound( Sound_ButtonClick ); } void * PlaySound_Chimes( void * peram ) { PlaySound( Sound_Chimes ); } void * PlaySound_Beep( void * peram ) { PlaySound( Sound_Beep ); } void * PlaySound_Blast( void * peram ) { PlaySound( Sound_Blast ); }
Thank you for your help,
Matt Dralle