engine result = slCreateEngine(&sEngineObject, 0, NULL, 0, NULL, NULL); // realize the engine result = (*sEngineObject)->Realize(sEngineObject, SL_BOOLEAN_FALSE); // get the engine interface, which is needed in order to create other objects result = (*sEngineObject)->GetInterface(sEngineObject, SL_IID_ENGINE, &sEngineEngine); // get the output mixer result = (*sEngineEngine)->CreateOutputMix(sEngineEngine, &sOutputMixObject, 0, 0, 0); // realize the output mix result = (*sOutputMixObject)->Realize(sOutputMixObject, SL_BOOLEAN_FALSE); if (mFormat == OBOE_AUDIO_FORMAT_UNSPECIFIED){ mFormat = (__ANDROID_API__ < __ANDROID_API_L__) ? OBOE_AUDIO_FORMAT_PCM_I16 : OBOE_AUDIO_FORMAT_PCM_FLOAT; } if (mFramesPerCallback != OBOE_UNSPECIFIED) { mFramesPerBurst = mFramesPerCallback; } else if (mFramesPerBurst != OBOE_UNSPECIFIED) { // set from defaultFramesPerBurst mFramesPerCallback = mFramesPerBurst; } else { mFramesPerBurst = mFramesPerCallback = DEFAULT_FRAMES_PER_CALLBACK; } mBytesPerCallback = mFramesPerCallback * getBytesPerFrame(); mCallbackBuffer = new uint8_t[mBytesPerCallback]; SLuint32 bitsPerSample = getBytesPerSample() * OBOE_BITS_PER_BYTE; SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, // locatorType static_cast<SLuint32>(mBurstsPerBuffer)}; // numBuffers // SLuint32 chanMask = SL_SPEAKER_FRONT_LEFT|SL_SPEAKER_FRONT_RIGHT; SLDataFormat_PCM format_pcm = { SL_DATAFORMAT_PCM, // formatType (SLuint32) mChannelCount, // numChannels (SLuint32) (mSampleRate * OBOE_MILLIS_PER_SECOND), // milliSamplesPerSec bitsPerSample, // bitsPerSample bitsPerSample, // containerSize; (SLuint32) chanCountToChanMask(mChannelCount), // channelMask s_getDefaultByteOrder(), }; SLDataSource audioSrc = {&loc_bufq, &format_pcm}; // configure audio sink SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, sOutputMixObject}; SLDataSink audioSnk = {&loc_outmix, NULL}; const SLInterfaceID ids[] = {SL_IID_BUFFERQUEUE}; const SLboolean req[] = {SL_BOOLEAN_TRUE}; // The Player result = (*sEngineEngine)->CreateAudioPlayer(sEngineEngine, &bqPlayerObject_ , &audioSrc, &audioSnk, sizeof(ids) / sizeof(ids[0]), ids, req result = (*bqPlayerObject_)->Realize(bqPlayerObject_, SL_BOOLEAN_FALSE); result = (*bqPlayerObject_)->GetInterface(bqPlayerObject_, SL_IID_PLAY, &bqPlayerPlay_); // The BufferQueue result = (*bqPlayerObject_)->GetInterface(bqPlayerObject_, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bq_); // The register BufferQueue callback result = (*bq_)->RegisterCallback(bq_, bqPlayerCallback, this); mSharingMode = OBOE_SHARING_MODE_SHARED; mBufferCapacityInFrames = mFramesPerBurst * mBurstsPerBuffer; return OBOE_OK; } Open a stream using OpenSL ES 60+ lines of code DroidCon Berlin - 2018