它应该很简单:
private void startPlaying() {
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(mFileName);
BassBoost bassBoost = new BassBoost(0, mPlayer.getAudioSessionId());
mPlayer.attachAuxEffect(bassBoost.getId());
bassBoost.setStrength((short)1000);
bassBoost.setEnabled(true);
mPlayer.setAuxEffectSendLevel(1.0f);
mPlayer.prepare();
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mPlayer.start();
}
});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new RuntimeException(e);
}
}
当我尝试时,它很安静,并且我在日志中收到错误 (-22,0)。如果我评论之间的线条BassBoost bassBoost = ...
,mPlayer.setAuxEffectSendLevel
它会播放声音。
我浏览了文档,但我找不到错误。清单中的权限:
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>