0

我试图在android中实现bassboost效果..但是没有效果..我使用以下代码来实现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();

  }

 }
4

1 回答 1

0

错误 38表示您在问MediaPlayer to do something when in the wrong state.You won't be able to fathom your error just from this

无论何时您调用setDataSource()它,您都需要prepare()再次调用它。将其视为加载文件,准备播放。

编辑

您在创建时已经将您的 bassboost 与您的媒体播放器连接起来。所以删除这个 mp.attachAuxEffect(boost.getId());

于 2015-05-11T07:22:46.783 回答