Handle unsupported equalizer

This commit is contained in:
Christopher Eby 2012-02-13 00:32:14 -06:00
parent 7876993a11
commit ee9f8b05ae

View File

@ -370,7 +370,11 @@ public final class PlaybackService extends Service
mMediaPlayer.setOnErrorListener(this); mMediaPlayer.setOnErrorListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
try {
mEqualizer = new CompatEq(mMediaPlayer); mEqualizer = new CompatEq(mMediaPlayer);
} catch (IllegalArgumentException e) {
// equalizer not supported
}
} }
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
@ -559,10 +563,12 @@ public final class PlaybackService extends Service
// In Gingerbread and above, MediaPlayer no longer accepts volumes // In Gingerbread and above, MediaPlayer no longer accepts volumes
// > 1.0. So we use an equalizer instead. // > 1.0. So we use an equalizer instead.
CompatEq eq = mEqualizer; CompatEq eq = mEqualizer;
if (eq != null) {
short gain = (short)(2000 * Math.log10(base)); short gain = (short)(2000 * Math.log10(base));
for (short i = eq.getNumberOfBands(); --i != -1; ) { for (short i = eq.getNumberOfBands(); --i != -1; ) {
eq.setBandLevel(i, gain); eq.setBandLevel(i, gain);
} }
}
base = 1.0f; base = 1.0f;
} }