Reputation: 2244
I'm attempting to play an audio file using OpenAl, but it's not actually playing anything. When I check if the audio file is playing after calling alSourcePlay, the state is still AL_INITIAL.
Here's where I play the audio:
// Make sure the audio source ident is valid and usable
if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[audioID])
return false;
int sourceAudioState = 0;
if(!alIsSource(mAudioSources[audioID]) == AL_TRUE) return false;
alGetError();
// Are we currently playing the audio source?
alGetSourcei( mAudioSources[audioID], AL_SOURCE_STATE, &sourceAudioState );
if ( sourceAudioState == AL_PLAYING )
{
printf("Currently playing!\n");
if ( forceRestart )
stopAudio( audioID );
else
return false; // Not forced, so we don't do anything
}
alSourcePlay( mAudioSources[ audioID ] );
if ( checkALError( "playAudio::alSourcePlay: ") )
return false;
alGetSourcei( mAudioSources[audioID], AL_SOURCE_STATE, &sourceAudioState );
printState(sourceAudioState);
if(sourceAudioState == AL_PLAYING)
{
printf("Now playing!\n\n");
}
return true;
mAudioSources is an array of buffers created by alGenBuffers. The file is loaded with
mAudioBuffers[bufferID] = alutCreateBufferFromFile(filename.c_str());
Which doesn't cause an error in alGetError. Any ideas?
Upvotes: 1
Views: 1816
Reputation: 4817
alutCreateBufferFromFile
will not cause an error in alGetError
. You have to use alutGetError
(note the prefix alut
instead of al
) instead. If alutCreateBufferFromFile
fails, it will return AL_NONE
which is a valid buffer: the NULL
buffer which will not be played.
Check the ALUT documentation for information on alutGetError
as well as the OpenAL Specs.
Upvotes: 3