Android 为什么onCompletionListener会立即启动并附带音频效果?

Android 为什么onCompletionListener会立即启动并附带音频效果?,android,android-mediaplayer,Android,Android Mediaplayer,当我添加代码以附加BassBoost效果时,我的MediaPlayer的onCompletionListener会立即启动。以下是相关代码: player.setDataSource(context, Uri.parse(song.filename)); // everything is fine if I comment out these 3 lines BassBoost boost = new BassBoost(0, player.getAudioSessionId()); boos

当我添加代码以附加
BassBoost
效果时,我的
MediaPlayer
onCompletionListener
会立即启动。以下是相关代码:

player.setDataSource(context, Uri.parse(song.filename));

// everything is fine if I comment out these 3 lines
BassBoost boost = new BassBoost(0, player.getAudioSessionId());
boost.setStrength((short) 1000);
player.attachAuxEffect(boost.getId());

player.prepare();
player.start();
我尝试过这个特定代码的顺序,但没有用。最后,我在完成处理程序中记录了
getCurrentPosition()
getDuration()
值,您不知道吗:它们都是零


我目前的想法是,附加效果需要异步准备,但我无法找到任何进一步的线索。

我从另一个被回答的问题中找到了答案。如果在效果构造函数中指定音频会话,然后调用
attachAuxEffect
,则会失败。这项工作:

BassBoost boost = new BassBoost(0, player.getAudioSessionId());
boost.setStrength((short) 1000);
// ALREADY ATTACHED IN CONSTRUCTOR ... player.attachAuxEffect(boost.getId());