+ alSourceUnqueueBuffers(mSource, 1, &buffer);
+
+ Buffer::StreamStatus status = mBuffer->stream(buffer);
+
+ if (status == Buffer::STREAM_OK)
+ {
+ alSourceQueueBuffers(mSource, 1, &buffer);
+ }
+ else if (status == Buffer::STREAM_EOF)
+ {
+ if (!mQueue.empty())
+ {
+ // begin the next buffer in the queue
+ mExpired.push_back(mBuffer);
+ mBuffer = mQueue.front();
+ mQueue.pop();
+ mBuffer->beginStream(mSource, 1);
+ }
+ else if (mIsLooping)
+ {
+ // restart from the beginning
+ mBuffer->rewind();
+ mBuffer->stream(buffer);
+ alSourceQueueBuffers(mSource, 1, &buffer);
+ }
+ }
+ else if (status == Buffer::STREAM_WRONG)
+ {
+ clear();
+ mBuffer->beginStream(mSource, 1);
+ }
+ }
+
+ ALenum state;
+ alGetSourcei(mSource, AL_SOURCE_STATE, &state);
+
+ // restart playing if we're stopped but supposed to be playing... this
+ // means we didn't queue enough and the audio skipped
+ if (mIsPlaying && state != AL_PLAYING)
+ {
+ alSourcePlay(mSource);