From ee61c639f3d01ed523e9b45bd4e775053f38413c Mon Sep 17 00:00:00 2001 From: Qiming Date: Tue, 8 Nov 2022 18:12:19 +0800 Subject: [PATCH] =?UTF-8?q?AudioEffect=20-=20Fixed=20a=20typo;=20Kotlin?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AudioEffectController.kt | 2 +- .../listener/AudioEffectCallback.kt | 2 +- .../ffmpeg/activity/AudioEffectActivity.kt | 39 ++++++++++--------- .../ffmpeg/activity/EqualizerActivity.kt | 4 +- .../frank/ffmpeg/adapter/EqualizerAdapter.kt | 6 +-- ...SeeBarListener.kt => OnSeekBarListener.kt} | 2 +- 6 files changed, 29 insertions(+), 26 deletions(-) rename app/src/main/java/com/frank/ffmpeg/listener/{OnSeeBarListener.kt => OnSeekBarListener.kt} (72%) 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 6f7db41..7bac240 100644 --- a/AndroidMedia/src/main/java/com/frank/androidmedia/controller/AudioEffectController.kt +++ b/AndroidMedia/src/main/java/com/frank/androidmedia/controller/AudioEffectController.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? = mAudioEffectCallback?.getSeeBarList() + val seekBarList: List? = mAudioEffectCallback?.getSeekBarList() if (mBands > 0 && seekBarList != null && mEqualizer != null) { for (band in 0 until mBands) { seekBarList[band].progress = mEqualizer!!.getBandLevel(band.toShort()) - minEQLevel diff --git a/AndroidMedia/src/main/java/com/frank/androidmedia/listener/AudioEffectCallback.kt b/AndroidMedia/src/main/java/com/frank/androidmedia/listener/AudioEffectCallback.kt index 1b61d08..74a661f 100644 --- a/AndroidMedia/src/main/java/com/frank/androidmedia/listener/AudioEffectCallback.kt +++ b/AndroidMedia/src/main/java/com/frank/androidmedia/listener/AudioEffectCallback.kt @@ -12,7 +12,7 @@ import java.util.ArrayList */ interface AudioEffectCallback { - fun getSeeBarList(): List? + fun getSeekBarList(): List? fun setEqualizerList(maxProgress: Int, equalizerList: ArrayList>) 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 e9f38cd..82ea033 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/AudioEffectActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/AudioEffectActivity.kt @@ -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>) { - if (equalizerAdapter != null) { - equalizerAdapter!!.setMaxProgress(maxProgress) - equalizerAdapter!!.setEqualizerList(equalizerList) + equalizerAdapter?.let { + it.setMaxProgress(maxProgress) + it.setEqualizerList(equalizerList) } } - override fun getSeeBarList(): List? { + override fun getSeekBarList(): List? { return equalizerAdapter?.getSeekBarList() } diff --git a/app/src/main/java/com/frank/ffmpeg/activity/EqualizerActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/EqualizerActivity.kt index 083a299..12cea5a 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/EqualizerActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/EqualizerActivity.kt @@ -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 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/java/com/frank/ffmpeg/adapter/EqualizerAdapter.kt b/app/src/main/java/com/frank/ffmpeg/adapter/EqualizerAdapter.kt index 307504f..9af0e7f 100644 --- a/app/src/main/java/com/frank/ffmpeg/adapter/EqualizerAdapter.kt +++ b/app/src/main/java/com/frank/ffmpeg/adapter/EqualizerAdapter.kt @@ -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() { +class EqualizerAdapter(private val context: Context, private val onSeekBarListener: OnSeekBarListener?) : RecyclerView.Adapter() { private var equalizerList: List>? = ArrayList() private val seekBarList = ArrayList() @@ -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) } }) } diff --git a/app/src/main/java/com/frank/ffmpeg/listener/OnSeeBarListener.kt b/app/src/main/java/com/frank/ffmpeg/listener/OnSeekBarListener.kt similarity index 72% rename from app/src/main/java/com/frank/ffmpeg/listener/OnSeeBarListener.kt rename to app/src/main/java/com/frank/ffmpeg/listener/OnSeekBarListener.kt index 73fa736..611ed97 100644 --- a/app/src/main/java/com/frank/ffmpeg/listener/OnSeeBarListener.kt +++ b/app/src/main/java/com/frank/ffmpeg/listener/OnSeekBarListener.kt @@ -1,5 +1,5 @@ package com.frank.ffmpeg.listener -interface OnSeeBarListener { +interface OnSeekBarListener { fun onProgress(index: Int, progress: Int) } \ No newline at end of file