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) {
try {
mEqualizer!!.usePreset(arg2.toShort())
val seekBarList: List<SeekBar>? = mAudioEffectCallback?.getSeeBarList()
val seekBarList: List<SeekBar>? = mAudioEffectCallback?.getSeekBarList()
if (mBands > 0 && seekBarList != null && mEqualizer != null) {
for (band in 0 until mBands) {
seekBarList[band].progress = mEqualizer!!.getBandLevel(band.toShort()) - minEQLevel

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

@ -12,12 +12,12 @@ import androidx.recyclerview.widget.RecyclerView
import com.frank.ffmpeg.AudioPlayer
import com.frank.ffmpeg.R
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 java.lang.StringBuilder
import java.util.ArrayList
class EqualizerActivity : BaseActivity(), OnSeeBarListener {
class EqualizerActivity : BaseActivity(), OnSeekBarListener {
// unit: Hz gain:0-20
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

@ -10,7 +10,7 @@ import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.frank.ffmpeg.R
import com.frank.ffmpeg.listener.OnSeeBarListener
import com.frank.ffmpeg.listener.OnSeekBarListener
import java.util.ArrayList
@ -20,7 +20,7 @@ import java.util.ArrayList
* @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 val seekBarList = ArrayList<SeekBar>()
@ -51,7 +51,7 @@ class EqualizerAdapter(private val context: Context, private val onSeeBarListene
}
override fun onStopTrackingTouch(seekBar: SeekBar) {
onSeeBarListener?.onProgress(i, seekBar.progress)
onSeekBarListener?.onProgress(i, seekBar.progress)
}
})
}

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