AudioEffect - Fixed a typo; Kotlin风格代码优化

pull/222/head
Qiming 2 years ago
parent becc4e8773
commit ee61c639f3
  1. 2
      AndroidMedia/src/main/java/com/frank/androidmedia/controller/AudioEffectController.kt
  2. 2
      AndroidMedia/src/main/java/com/frank/androidmedia/listener/AudioEffectCallback.kt
  3. 39
      app/src/main/java/com/frank/ffmpeg/activity/AudioEffectActivity.kt
  4. 4
      app/src/main/java/com/frank/ffmpeg/activity/EqualizerActivity.kt
  5. 6
      app/src/main/java/com/frank/ffmpeg/adapter/EqualizerAdapter.kt
  6. 2
      app/src/main/java/com/frank/ffmpeg/listener/OnSeekBarListener.kt

@ -91,7 +91,7 @@ open class AudioEffectController(audioEffectCallback: AudioEffectCallback) {
override fun onItemSelected(arg0: AdapterView<*>, arg1: View, arg2: Int, arg3: Long) { override fun onItemSelected(arg0: AdapterView<*>, arg1: View, arg2: Int, arg3: Long) {
try { try {
mEqualizer!!.usePreset(arg2.toShort()) mEqualizer!!.usePreset(arg2.toShort())
val seekBarList: List<SeekBar>? = mAudioEffectCallback?.getSeeBarList() val seekBarList: List<SeekBar>? = mAudioEffectCallback?.getSeekBarList()
if (mBands > 0 && seekBarList != null && mEqualizer != null) { if (mBands > 0 && seekBarList != null && mEqualizer != null) {
for (band in 0 until mBands) { for (band in 0 until mBands) {
seekBarList[band].progress = mEqualizer!!.getBandLevel(band.toShort()) - minEQLevel seekBarList[band].progress = mEqualizer!!.getBandLevel(band.toShort()) - minEQLevel

@ -12,7 +12,7 @@ import java.util.ArrayList
*/ */
interface AudioEffectCallback { interface AudioEffectCallback {
fun getSeeBarList(): List<SeekBar>? fun getSeekBarList(): List<SeekBar>?
fun setEqualizerList(maxProgress: Int, equalizerList: ArrayList<Pair<*, *>>) fun setEqualizerList(maxProgress: Int, equalizerList: ArrayList<Pair<*, *>>)

@ -15,7 +15,7 @@ import com.frank.androidmedia.controller.AudioEffectController
import com.frank.androidmedia.listener.AudioEffectCallback import com.frank.androidmedia.listener.AudioEffectCallback
import com.frank.ffmpeg.R import com.frank.ffmpeg.R
import com.frank.ffmpeg.adapter.EqualizerAdapter import com.frank.ffmpeg.adapter.EqualizerAdapter
import com.frank.ffmpeg.listener.OnSeeBarListener import com.frank.ffmpeg.listener.OnSeekBarListener
import com.frank.ffmpeg.util.FileUtil import com.frank.ffmpeg.util.FileUtil
import com.frank.ffmpeg.view.VisualizerView import com.frank.ffmpeg.view.VisualizerView
import java.io.IOException import java.io.IOException
@ -25,11 +25,11 @@ import java.util.ArrayList
* Audio effect: equalizer, enhancer, visualizer, bassBoost * Audio effect: equalizer, enhancer, visualizer, bassBoost
* Created by frank on 2020/10/20. * Created by frank on 2020/10/20.
*/ */
class AudioEffectActivity : BaseActivity(), OnSeeBarListener, AudioEffectCallback { class AudioEffectActivity : BaseActivity(), OnSeekBarListener, AudioEffectCallback {
companion object { companion object {
private val audioPath = Environment.getExternalStorageDirectory().path + "/tiger.mp3" private var audioPath = Environment.getExternalStorageDirectory().path + "/tiger.mp3"
} }
private var mPlayer: MediaPlayer? = null private var mPlayer: MediaPlayer? = null
@ -48,12 +48,13 @@ class AudioEffectActivity : BaseActivity(), OnSeeBarListener, AudioEffectCallbac
Manifest.permission.MODIFY_AUDIO_SETTINGS) Manifest.permission.MODIFY_AUDIO_SETTINGS)
private val onPreparedListener = MediaPlayer.OnPreparedListener { private val onPreparedListener = MediaPlayer.OnPreparedListener {
mAudioEffectController = AudioEffectController(this) mAudioEffectController = AudioEffectController(this).apply {
mAudioEffectController?.setupEqualizer(mPlayer!!.audioSessionId) setupEqualizer(mPlayer!!.audioSessionId)
mAudioEffectController?.setupPresetStyle(this@AudioEffectActivity, spinnerStyle!!) setupPresetStyle(this@AudioEffectActivity, spinnerStyle!!)
mAudioEffectController?.setupBassBoost(mPlayer!!.audioSessionId, barBassBoost!!) setupBassBoost(mPlayer!!.audioSessionId, barBassBoost!!)
mAudioEffectController?.setLoudnessEnhancer(mPlayer!!.audioSessionId, barEnhancer!!) setLoudnessEnhancer(mPlayer!!.audioSessionId, barEnhancer!!)
mAudioEffectController?.setupVisualizer(mPlayer!!.audioSessionId) setupVisualizer(mPlayer!!.audioSessionId)
}
mPlayer!!.start() mPlayer!!.start()
} }
@ -95,10 +96,11 @@ class AudioEffectActivity : BaseActivity(), OnSeeBarListener, AudioEffectCallbac
return return
} }
try { try {
mPlayer = MediaPlayer() mPlayer = MediaPlayer().apply {
mPlayer!!.setDataSource(audioPath) setDataSource(audioPath)
mPlayer!!.setOnPreparedListener(onPreparedListener) setOnPreparedListener(onPreparedListener)
mPlayer!!.prepareAsync() prepareAsync()
}
} catch (e: IOException) { } catch (e: IOException) {
Log.e("AudioEffect", "play error=$e") Log.e("AudioEffect", "play error=$e")
} }
@ -113,17 +115,18 @@ class AudioEffectActivity : BaseActivity(), OnSeeBarListener, AudioEffectCallbac
} }
override fun onSelectedFile(filePath: String) { override fun onSelectedFile(filePath: String) {
audioPath = filePath
initPlayer()
} }
override fun setEqualizerList(maxProgress: Int, equalizerList: ArrayList<Pair<*, *>>) { override fun setEqualizerList(maxProgress: Int, equalizerList: ArrayList<Pair<*, *>>) {
if (equalizerAdapter != null) { equalizerAdapter?.let {
equalizerAdapter!!.setMaxProgress(maxProgress) it.setMaxProgress(maxProgress)
equalizerAdapter!!.setEqualizerList(equalizerList) it.setEqualizerList(equalizerList)
} }
} }
override fun getSeeBarList(): List<SeekBar>? { override fun getSeekBarList(): List<SeekBar>? {
return equalizerAdapter?.getSeekBarList() return equalizerAdapter?.getSeekBarList()
} }

@ -12,12 +12,12 @@ import androidx.recyclerview.widget.RecyclerView
import com.frank.ffmpeg.AudioPlayer import com.frank.ffmpeg.AudioPlayer
import com.frank.ffmpeg.R import com.frank.ffmpeg.R
import com.frank.ffmpeg.adapter.EqualizerAdapter import com.frank.ffmpeg.adapter.EqualizerAdapter
import com.frank.ffmpeg.listener.OnSeeBarListener import com.frank.ffmpeg.listener.OnSeekBarListener
import com.frank.ffmpeg.view.VisualizerView import com.frank.ffmpeg.view.VisualizerView
import java.lang.StringBuilder import java.lang.StringBuilder
import java.util.ArrayList import java.util.ArrayList
class EqualizerActivity : BaseActivity(), OnSeeBarListener { class EqualizerActivity : BaseActivity(), OnSeekBarListener {
// unit: Hz gain:0-20 // unit: Hz gain:0-20
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

@ -10,7 +10,7 @@ import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.frank.ffmpeg.R import com.frank.ffmpeg.R
import com.frank.ffmpeg.listener.OnSeeBarListener import com.frank.ffmpeg.listener.OnSeekBarListener
import java.util.ArrayList import java.util.ArrayList
@ -20,7 +20,7 @@ import java.util.ArrayList
* @desc Adapter of equalizer * @desc Adapter of equalizer
*/ */
class EqualizerAdapter(private val context: Context, private val onSeeBarListener: OnSeeBarListener?) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { class EqualizerAdapter(private val context: Context, private val onSeekBarListener: OnSeekBarListener?) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var equalizerList: List<Pair<*, *>>? = ArrayList() private var equalizerList: List<Pair<*, *>>? = ArrayList()
private val seekBarList = ArrayList<SeekBar>() private val seekBarList = ArrayList<SeekBar>()
@ -51,7 +51,7 @@ class EqualizerAdapter(private val context: Context, private val onSeeBarListene
} }
override fun onStopTrackingTouch(seekBar: SeekBar) { override fun onStopTrackingTouch(seekBar: SeekBar) {
onSeeBarListener?.onProgress(i, seekBar.progress) onSeekBarListener?.onProgress(i, seekBar.progress)
} }
}) })
} }

@ -1,5 +1,5 @@
package com.frank.ffmpeg.listener package com.frank.ffmpeg.listener
interface OnSeeBarListener { interface OnSeekBarListener {
fun onProgress(index: Int, progress: Int) fun onProgress(index: Int, progress: Int)
} }
Loading…
Cancel
Save