使用OpenSL ES的Android NDK测试应用程序

时间:2012-06-15 13:14:27

标签: android-ndk opensl

我开发了一个NDK应用程序(我从控制台运行)并使用Android 4.0.3在TI AM37x硬件上运行。这个应用程序使用OpenSL API,我试图在硬件上播放SDCard的歌曲。相同的路径正在使用NDK示例代码(URI播放),但我无法听到来自我的应用程序的音频。有谁有想法吗? 我的代码流程如下:

    result=slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);
    ....
    result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
    ....
    result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine);
    ....
    result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 1, ids, req);
    ....
    Realize, GetInterface ...
    ....
    SLchar path[] = "/mnt/sdcard/Audio/Msong.mp3" ;
    SLDataLocator_URI loc_uri = {SL_DATALOCATOR_URI, path};
    SLDataFormat_MIME format_mime = {SL_DATAFORMAT_MIME, NULL,   
    SL_CONTAINERTYPE_UNSPECIFIED};
    SLDataSource audioSrcuri = {&loc_uri, &format_mime};
    ...
    result = (*engineEngine)->CreateAudioPlayer(engineEngine, &uriPlayerObject, 
                                             &audioSrcuri,&audioSnkuri, 1, idsuri, requri);
    ...
    result = (*uriPlayerObject)->Realize(uriPlayerObject, SL_BOOLEAN_FALSE);
    ...
    result = (*uriPlayerObject)->GetInterface(uriPlayerObject, SL_IID_PLAY, 
                                                                  &uriPlayerPlay);
    ...
    result = (*uriPlayerObject)->GetInterface(uriPlayerObject, SL_IID_SEEK, 
                                                                   &uriPlayerSeek);
    ...
    result = (*uriPlayerPlay)->SetPlayState(uriPlayerPlay, SL_PLAYSTATE_PLAYING);

1 个答案:

答案 0 :(得分:1)

您需要配置audioSnk

// create output mix
const SLInterfaceID ids[1] = {SL_IID_ENVIRONMENTALREVERB};
const SLboolean req[1] = {SL_BOOLEAN_FALSE};
result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 1, ids, req);

// realize the output mix
result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);

...

// configure audio sink
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
SLDataSink audioSnk = {&loc_outmix, NULL};