making the equalizer more reliable

This commit is contained in:
tibbi 2021-02-05 13:21:30 +01:00
parent 3d17195396
commit c94d29e986
2 changed files with 9 additions and 8 deletions

View file

@ -79,8 +79,8 @@ class EqualizerActivity : SimpleActivity() {
val newValue = newProgress + minValue
try {
if (equalizer.getBandLevel(band.toShort()) != newValue.toShort()) {
equalizer.setBandLevel(band.toShort(), newValue.toShort())
if ((MusicService.mEqualizer ?: equalizer).getBandLevel(band.toShort()) != newValue.toShort()) {
(MusicService.mEqualizer ?: equalizer).setBandLevel(band.toShort(), newValue.toShort())
bands[band.toShort()] = newValue.toInt()
}
} catch (e: Exception) {
@ -151,10 +151,10 @@ class EqualizerActivity : SimpleActivity() {
bandSeekBars[band].progress = progress!!.toInt()
val newValue = progress + minValue
equalizer.setBandLevel(band.toShort(), newValue.toShort())
(MusicService.mEqualizer ?: equalizer).setBandLevel(band.toShort(), newValue.toShort())
}
} else {
val presetName = equalizer.getPresetName(presetId.toShort())
val presetName = (MusicService.mEqualizer ?: equalizer).getPresetName(presetId.toShort())
if (presetName.isEmpty()) {
config.equalizerPreset = EQUALIZER_PRESET_CUSTOM
equalizer_preset.text = getString(R.string.custom)
@ -162,11 +162,11 @@ class EqualizerActivity : SimpleActivity() {
equalizer_preset.text = presetName
}
equalizer.usePreset(presetId.toShort())
(MusicService.mEqualizer ?: equalizer).usePreset(presetId.toShort())
val lowestBandLevel = equalizer.bandLevelRange?.get(0)
for (band in 0 until equalizer.numberOfBands) {
val level = equalizer.getBandLevel(band.toShort()).minus(lowestBandLevel!!)
val lowestBandLevel = (MusicService.mEqualizer ?: equalizer).bandLevelRange?.get(0)
for (band in 0 until (MusicService.mEqualizer ?: equalizer).numberOfBands) {
val level = (MusicService.mEqualizer ?: equalizer).getBandLevel(band.toShort()).minus(lowestBandLevel!!)
bandSeekBars[band].progress = level
}
}

View file

@ -123,6 +123,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
destroyPlayer()
SongsDatabase.destroyInstance()
mMediaSession?.isActive = false
mEqualizer?.release()
mSleepTimer?.cancel()
config.sleepInTS = 0L
}