
注意这儿的代码:
const SLInterfaceID ids[2] = {SL_IID_BUFFERQUEUE,SL_IID_VOLUME};
const SLboolean req[2] = {SL_BOOLEAN_TRUE,SL_BOOLEAN_TRUE};
(*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject, &slDataSource, &audioSnk, 2, ids, req);
//初始化播放器
(*pcmPlayerObject)->Realize(pcmPlayerObject, SL_BOOLEAN_FALSE);
// 得到接口后调用 获取Player接口
(*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_PLAY, &pcmPlayerPlay);
(*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_VOLUME, &pcmVolumePlay);
void HAudio::setVolume(int percent) {
volumePercent = percent;
if(pcmVolumePlay != NULL)
{
if(percent > 30)
{
(*pcmVolumePlay)->SetVolumeLevel(pcmVolumePlay, (100 - percent) * -20);
}
else if(percent > 25)
{
(*pcmVolumePlay)->SetVolumeLevel(pcmVolumePlay, (100 - percent) * -22);
}
else if(percent > 20)
{
(*pcmVolumePlay)->SetVolumeLevel(pcmVolumePlay, (100 - percent) * -25);
}
else if(percent > 15)
{
(*pcmVolumePlay)->SetVolumeLevel(pcmVolumePlay, (100 - percent) * -28);
}
else if(percent > 10)
{
(*pcmVolumePlay)->SetVolumeLevel(pcmVolumePlay, (100 - percent) * -30);
}
else if(percent > 5)
{
(*pcmVolumePlay)->SetVolumeLevel(pcmVolumePlay, (100 - percent) * -34);
}
else if(percent > 3)
{
(*pcmVolumePlay)->SetVolumeLevel(pcmVolumePlay, (100 - percent) * -37);
}
else if(percent > 0)
{
(*pcmVolumePlay)->SetVolumeLevel(pcmVolumePlay, (100 - percent) * -40);
}
else{
(*pcmVolumePlay)->SetVolumeLevel(pcmVolumePlay, (100 - percent) * -100);
}
}
}

const SLInterfaceID ids[3] = {SL_IID_BUFFERQUEUE,SL_IID_VOLUME,SL_IID_MUTESOLO};
const SLboolean req[3] = {SL_BOOLEAN_TRUE,SL_BOOLEAN_TRUE,SL_BOOLEAN_TRUE};
(*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject, &slDataSource, &audioSnk, 3, ids, req);
//初始化播放器
(*pcmPlayerObject)->Realize(pcmPlayerObject, SL_BOOLEAN_FALSE);
// 得到接口后调用 获取Player接口
(*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_PLAY, &pcmPlayerPlay);
(*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_VOLUME, &pcmVolumePlay);
(*pcmPlayerObject)->GetInterface(
pcmPlayerObject,
SL_IID_MUTESOLO,
&pcmPlayPlayerMuteSolo);
void HAudio::setStereoVolume() {
(*pcmPlayPlayerMuteSolo)->SetChannelMute(
pcmPlayPlayerMuteSolo,
1, //0右声道1左声道
false //声道是否开启
);
(*pcmPlayPlayerMuteSolo)->SetChannelMute(
pcmPlayPlayerMuteSolo,
0, //0右声道1左声道
false //声道是否开启
);
}
void HAudio::setRightVolume() {
(*pcmPlayPlayerMuteSolo)->SetChannelMute(
pcmPlayPlayerMuteSolo,
1, //0右声道1左声道
false //声道是否开启
);
(*pcmPlayPlayerMuteSolo)->SetChannelMute(
pcmPlayPlayerMuteSolo,
0, //0右声道1左声道
true //声道是否开启
);
}
void HAudio::setLeftVolume() {
(*pcmPlayPlayerMuteSolo)->SetChannelMute(
pcmPlayPlayerMuteSolo,
0, //0右声道1左声道
false //声道是否开启
);
(*pcmPlayPlayerMuteSolo)->SetChannelMute(
pcmPlayPlayerMuteSolo,
1, //0右声道1左声道
true //声道是否开启
);
}
网友评论