Skip to content

Instantly share code, notes, and snippets.

@yorung
Created December 12, 2015 08:34
Show Gist options
  • Select an option

  • Save yorung/301c578cef5274a196b8 to your computer and use it in GitHub Desktop.

Select an option

Save yorung/301c578cef5274a196b8 to your computer and use it in GitHub Desktop.
void Voice::Play(bool loop)
{
if (!IsReady()) {
return;
}
auto playback = [](SLAndroidSimpleBufferQueueItf q, void* context_) {
WaveContext* context = (WaveContext*)context_;
int totalSize;
const void* buf = RiffFindChunk(context->fileImg, "data", &totalSize);
SLCall(q, Enqueue, (char*)buf, totalSize);
};
auto doNothing = [](SLAndroidSimpleBufferQueueItf, void*) {};
SLCall(context->playerPlay, SetPlayState, SL_PLAYSTATE_STOPPED);
SLCall(context->playerBufferQueue, RegisterCallback, loop ? playback : doNothing, context);
SLCall(context->playerPlay, SetPlayState, SL_PLAYSTATE_PLAYING);
playback(context->playerBufferQueue, context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment