我已经尝试了在stackoverflow.com上找到的所有方法,这个均衡器实例根本没有响应。 我只想要它做基本的东西!
我的min项目API级别为16。
我在Galaxy S6(Android 5.1.1 API 22)上进行测试
// create : media player + equalizer
private void init() {
Log.d(TAG, "initMediaPlayer: ");
try {
mediaPlayer = new MediaPlayer();
equalizer = new Equalizer(0, mediaPlayer.getAudioSessionId());
if (equalizer.setEnabled(true) != Equalizer.SUCCESS) {
Log.d(TAG, "initMediaPlayer: FAILED");
return;
}
equalizer.usePreset((short) 0);
} catch (Exception e) {
Log.e(TAG, "initMediaPlayer: ", e);
}
}
// use next preset
private void useNextPreset() {
short presetCount = equalizer.getNumberOfPresets();
short index = equalizer.getCurrentPreset();
index++;
if (index >= presetCount) index = 0;
equalizer.usePreset(index);
Log.d(TAG, "useNextPreset: " + equalizer.getPresetName(index));
}
// show music picker
private void popPicker() {
popActivity(FilePickerIntent("audio/*"), new IntentRequestResultForward() {
@Override
public void onResult(boolean ok, Intent data) {
if (ok) play(data.getData());
}
});
}
// play music from uri
private void play(Uri uri) {
mediaPlayer.reset();
try {
mediaPlayer.setDataSource(getApplicationContext(), uri);
mediaPlayer.prepare();
mediaPlayer.start();
Log.d(TAG, "play: playing...");
} catch (Exception e) {
Log.e(TAG, "play: error ", e);
}
}
答案 0 :(得分:0)
为我工作,听到了一些优美的音乐。一定要包括
<uses-permission android:name="android.permission.INTERNET"/>
在您的清单中,application
标记上方。
答案 1 :(得分:0)