我开发了一个 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);