1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| SLEngineItf eng = CreateSL(); if (eng) { LOGE("CreateSL success! "); } else { LOGE("CreateSL failed! "); return -1; }
SLObjectItf mix = NULL; SLresult re = 0;
re = (*eng)->CreateOutputMix(eng, &mix, 0, 0, 0); if (re != SL_RESULT_SUCCESS) { LOGE("SL_RESULT_SUCCESS failed!"); return -1; }
re = (*mix)->Realize(mix, SL_BOOLEAN_FALSE); if (re != SL_RESULT_SUCCESS) { LOGE("(*mix)->Realize failed!"); return -1; }
SLDataLocator_OutputMix outmix = {SL_DATALOCATOR_OUTPUTMIX, mix}; SLDataSink audioSink = {&outmix, 0};
SLDataLocator_AndroidSimpleBufferQueue que = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 10};
SLDataFormat_PCM pcm = { SL_DATAFORMAT_PCM, 1, SL_SAMPLINGRATE_44_1, SL_PCMSAMPLEFORMAT_FIXED_16, SL_PCMSAMPLEFORMAT_FIXED_16, SL_SPEAKER_FRONT_LEFT, SL_BYTEORDER_LITTLEENDIAN }; SLDataSource ds = {&que, &pcm};
SLObjectItf player = NULL; SLPlayItf iplayer = NULL; SLAndroidSimpleBufferQueueItf pcmQue = NULL; const SLInterfaceID ids[] = {SL_IID_BUFFERQUEUE}; const SLboolean req[] = {SL_BOOLEAN_TRUE}; re = (*eng)->CreateAudioPlayer(eng, &player, &ds, &audioSink, sizeof(ids) / sizeof(SLInterfaceID), ids, req); if (re != SL_RESULT_SUCCESS) { LOGE("CreateAudioPlayer failed!"); } else { LOGE("CreateAudioPlayer success!"); } (*player)->Realize(player, SL_BOOLEAN_FALSE);
re = (*player)->GetInterface(player, SL_IID_PLAY, &iplayer); if (re != SL_RESULT_SUCCESS) { LOGE("GetInterface SL_IID_PLAY failed!"); } re = (*player)->GetInterface(player, SL_IID_BUFFERQUEUE, &pcmQue); if (re != SL_RESULT_SUCCESS) { LOGE("GetInterface SL_IID_BUFFERQUEUE failed!"); }
(*pcmQue)->RegisterCallback(pcmQue, pcmCallBack, 0);
(*iplayer)->SetPlayState(iplayer, SL_PLAYSTATE_PLAYING);
(*pcmQue)->Enqueue(pcmQue, "", 1);
|