我在Google Play商店上看到客户设备,这些设备的应用无法实现OpenSLES播放器对象。
静态SLObjectItf playerObject;
...
结果=(* playerObject)->实现(playerObject,SL_BOOLEAN_FALSE);
给出错误 SL_RESULT_CONTENT_UNSUPPORTED 。
// Configure data format.
static SLDataFormat_PCM pcm;
memset( &pcm, 0, sizeof(pcm) );
pcm.formatType = SL_DATAFORMAT_PCM;
pcm.numChannels = 1;
pcm.samplesPerSec = SL_SAMPLINGRATE_11_025;
pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
pcm.containerSize = 16;
pcm.channelMask = SL_SPEAKER_FRONT_CENTER;
pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;
// Configure Audio Source.
SLDataSource source;
source.pFormat = &pcm;
source.pLocator = &bufferQueue;
// Create engine
//LOGI("create audio engine");
result = slCreateEngine
(
&engineObject,
0, // numOptions
NULL,
0, // numInterfaces
NULL,
NULL
);
CHECK_SL( result, "slCreateEngine" );
result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
CHECK_SL( result, "engineObject->Realize" );
// get the engine interface, which is needed in order to create other objects
result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine);
CHECK_SL( result, "GetInterface ENGINE" );
result = (*engineEngine)->CreateOutputMix( engineEngine,&outputMixObject, 0, NULL, NULL );
CHECK_SL( result, "CreateOutputMix" );
result = (*outputMixObject)->Realize(outputMixObject,SL_BOOLEAN_FALSE);
CHECK_SL( result, "outputMixObject->Realize" );
SLDataLocator_OutputMix loc_outmix = { SL_DATALOCATOR_OUTPUTMIX,outputMixObject };
SLDataSink audioSnk = { &loc_outmix, NULL };
// Create Audio player.
const SLInterfaceID ids[2] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_VOLUME };
const SLboolean req[2] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_FALSE };
result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &source, &audioSnk, 2, ids, req);
CHECK_SL( result, "CreateAudioPlayer" );
// Realize Audio player.
result = (*playerObject)->Realize(playerObject, SL_BOOLEAN_FALSE);
CHECK_SL( result, "playerObject->Realize" );
我在以下设备上看到了这一点: 联想A1000,三星/ SM-T285,摩托罗拉/ Moto G(4),...
它在抱怨数据格式吗?这不是很奇怪:PCM频率为11025 Hz,16位。