我正在尝试AudioPlayer
使用缓冲队列源和输出混合接收器创建一个。我已将源配置为与 ndk 示例中显示的非常相似的 pcm 格式,但 OpenSL 拒绝SL_DATAFORMAT_PCM
(“数据格式 2”)。这对我来说没有任何意义。
这是错误(在三星 Galaxy S2 上):
02-27 15:43:47.315: E/libOpenSLES(12681): pAudioSrc: data format 2 not allowed
02-27 15:43:47.315: W/libOpenSLES(12681): Leaving Engine::CreateAudioPlayer (SL_RESULT_CONTENT_UNSUPPORTED)
这是相关的代码:
SLuint32 channels = 2;
SLuint32 speakers = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
SLuint32 sr = SL_SAMPLINGRATE_48;
//...
SLDataFormat_PCM format_pcm = {
SL_DATAFORMAT_PCM,
channels,
sr,
SL_PCMSAMPLEFORMAT_FIXED_16,
SL_PCMSAMPLEFORMAT_FIXED_16,
speakers,
SL_BYTEORDER_LITTLEENDIAN
};
// Configure audio player source
SLDataLocator_AndroidBufferQueue loc_bufq =
{SL_DATALOCATOR_ANDROIDBUFFERQUEUE, 2};
SLDataSource audioSrc = {&loc_bufq, &format_pcm};
// configure audio player sink
SLDataLocator_OutputMix loc_outmix =
{SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
SLDataSink audioSnk = {&loc_outmix, NULL};
// create audio player
const SLInterfaceID iidsOutPlayer[] = {SL_IID_ANDROIDBUFFERQUEUESOURCE};
const SLboolean reqsOutPlayer[] = {SL_BOOLEAN_TRUE};
result = (*engineItf)->CreateAudioPlayer(
engineItf,
&(outPlayerObject),
&audioSrc, &audioSnk,
1, iidsOutPlayer,reqsOutPlayer);
有谁知道这是什么原因造成的?谢谢!