2016-02-12 28 views
0

當我添加代碼以附加BassBoost效果時,我的的onCompletionListener立即被觸發。這裏的相關代碼:爲什麼onCompletionListener會立即觸發附加的AudioEffect?

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()值,你不知道它們:它們都是零!

我目前的想法是,附加效應需要異步準備,但我一直未能找到任何進一步的線索。

回答

0

我從另一個被回答的問題中找出了它。如果您在效果構造函數中指定音頻會話,然後調用attachAuxEffect,則會失敗。此作品:

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