我试图在android中实现bassboost效果..但没有效果..我使用以下代码进行低音效果;(我尝试使用全局音频会话ID并在清单文件中添加了权限) - >修改音频设置..
enter code here
BassBoost boost = new BassBoost(0,mp.getAudioSessionId());
boost.setEnabled(true);
boost.setStrength((Short)1000);
mp.attachAuxEffect(boost.getId());--->if i use this i'm getting(-38,0) or else no effect
mp.setSendLevel(1.0f);
我使用下面的代码进行低音增强效果。网络媒体播放器(-38,0)错误..请解决此问题..
enter code here
public class MainActivity extends Activity
{
MediaPlayer mediaplayer;
AssetFileDescriptor descriptor;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
setContentView(R.layout.activity_main);
mediaplayer = new MediaPlayer();
mediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
descriptor = MainActivity.this.getAssets().openFd("Kalimba.mp3");
} catch (IOException e1) {
e1.printStackTrace();
}
try {
mediaplayer.setDataSource(descriptor.getFileDescriptor(),
descriptor.getStartOffset(), descriptor.getLength());
} catch (IllegalArgumentException e1) {
e1.printStackTrace();
} catch (IllegalStateException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
descriptor.close();
} catch (IOException e1) {
e1.printStackTrace();
}
setUpBooster();
mediaplayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
}
public void setUpBooster() {
BassBoost booster = new BassBoost(0,0);//-->tried with sessionid also
booster.setStrength((short) 1000);
booster.setEnabled(true);
mediaplayer.attachAuxEffect(booster.getId());
mediaplayer.setAuxEffectSendLevel(1.0f);
try {
mediaplayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
}
答案 0 :(得分:0)
错误38 表示您询问MediaPlayer to do something when in the wrong state.
您将不会able to fathom your error just from this
。
只要您在其上致电setDataSource()
,您就需要再次prepare()
。可以把它想象成加载文件,准备播放。
修改强>
您已经在创建媒体播放器时附加了bassboost。请删除此
mp.attachAuxEffect(boost.getId());