diff --git a/AndroidMedia/src/main/java/com/frank/androidmedia/controller/AudioEffectController.kt b/AndroidMedia/src/main/java/com/frank/androidmedia/controller/AudioEffectController.kt index 1c9a3a0..49ae39d 100644 --- a/AndroidMedia/src/main/java/com/frank/androidmedia/controller/AudioEffectController.kt +++ b/AndroidMedia/src/main/java/com/frank/androidmedia/controller/AudioEffectController.kt @@ -2,6 +2,7 @@ package com.frank.androidmedia.controller import android.R import android.content.Context +import android.media.audiofx.BassBoost import android.media.audiofx.Equalizer import android.media.audiofx.PresetReverb import android.util.Log @@ -32,7 +33,8 @@ open class AudioEffectController(audioEffectCallback: AudioEffectCallback) { private var mPresetReverb: PresetReverb? = null private val reverbValues = ArrayList() -// private var seekBarList: List? = ArrayList() + + private var mBass: BassBoost? = null private var mAudioEffectCallback: AudioEffectCallback? = null @@ -43,6 +45,9 @@ open class AudioEffectController(audioEffectCallback: AudioEffectCallback) { mAudioEffectCallback = audioEffectCallback } + /** + * Setup AudioEffect of Equalizer, which has centerFrequency、band、bandLevel + */ fun setupEqualizer(audioSessionId: Int) { val equalizerList = ArrayList>() mEqualizer = Equalizer(0, audioSessionId) @@ -59,6 +64,9 @@ open class AudioEffectController(audioEffectCallback: AudioEffectCallback) { mAudioEffectCallback?.setEqualizerList(maxEQLevel - minEQLevel, equalizerList) } + /** + * Setup preset style, which associates to Equalizer + */ fun setupPresetStyle(context: Context, spinnerStyle: Spinner) { for (i in 0 until mEqualizer!!.numberOfPresets) { reverbValues.add(mEqualizer!!.getPresetName(i.toShort())) @@ -86,11 +94,33 @@ open class AudioEffectController(audioEffectCallback: AudioEffectCallback) { } } + /** + * Setup AudioEffect of BassBoost + */ + fun setupBassBoost(audioSessionId: Int, barBassBoost: SeekBar) { + mBass = BassBoost(0, audioSessionId) + mBass!!.enabled = true + // 0~1000 + barBassBoost.max = 1000 + barBassBoost.progress = 0 + barBassBoost.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + // set the strength of bass boost + mBass!!.setStrength(progress.toShort()) + } + + override fun onStartTrackingTouch(seekBar: SeekBar) {} + + override fun onStopTrackingTouch(seekBar: SeekBar) {} + }) + } + fun onEqualizerProgress(index: Int, progress: Int) { mEqualizer!!.setBandLevel(index.toShort(), (progress + minEQLevel).toShort()) } fun release() { + mBass?.release() mEqualizer?.release() mPresetReverb?.release() } diff --git a/app/src/main/java/com/frank/ffmpeg/activity/AudioEffectActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/AudioEffectActivity.kt index be05b83..c89bf5e 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/AudioEffectActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/AudioEffectActivity.kt @@ -37,7 +37,6 @@ class AudioEffectActivity : BaseActivity(), OnSeeBarListener, AudioEffectCallbac } private var mPlayer: MediaPlayer? = null - private var mBass: BassBoost? = null private var spinnerStyle: Spinner? = null private var spinnerReverb: Spinner? = null private var barBassBoost: SeekBar? = null @@ -58,7 +57,7 @@ class AudioEffectActivity : BaseActivity(), OnSeeBarListener, AudioEffectCallbac audioEffectController = AudioEffectController(this) audioEffectController?.setupEqualizer(mPlayer!!.audioSessionId) audioEffectController?.setupPresetStyle(this@AudioEffectActivity, spinnerStyle!!) - setupBassBoost() + audioEffectController?.setupBassBoost(mPlayer!!.audioSessionId, barBassBoost!!) setLoudnessEnhancer() setupVisualizer() @@ -115,24 +114,6 @@ class AudioEffectActivity : BaseActivity(), OnSeeBarListener, AudioEffectCallbac audioEffectController?.onEqualizerProgress(index, progress) } - private fun setupBassBoost() { - mBass = BassBoost(0, mPlayer!!.audioSessionId) - mBass!!.enabled = true - // 0--1000 - barBassBoost!!.max = 1000 - barBassBoost!!.progress = 0 - barBassBoost!!.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { - // set the strength of bass boost - mBass!!.setStrength(progress.toShort()) - } - - override fun onStartTrackingTouch(seekBar: SeekBar) {} - - override fun onStopTrackingTouch(seekBar: SeekBar) {} - }) - } - @RequiresApi(Build.VERSION_CODES.KITKAT) private fun setLoudnessEnhancer() { loudnessEnhancer = LoudnessEnhancer(mPlayer!!.audioSessionId) @@ -195,7 +176,7 @@ class AudioEffectActivity : BaseActivity(), OnSeeBarListener, AudioEffectCallbac override fun onDestroy() { super.onDestroy() - mBass?.release() + audioEffectController?.release() loudnessEnhancer?.release() releaseVisualizer() mPlayer?.release()