catch exception

pull/166/head
xufulong 4 years ago
parent ec4f9ee641
commit 29f7706ad9
  1. 13
      app/src/main/java/com/frank/ffmpeg/activity/AudioEffectActivity.kt
  2. 21
      app/src/main/java/com/frank/ffmpeg/format/AudioVisualizer.java

@ -63,7 +63,8 @@ class AudioEffectActivity : AppCompatActivity(), OnSeeBarListener {
private val onPreparedListener = MediaPlayer.OnPreparedListener { private val onPreparedListener = MediaPlayer.OnPreparedListener {
setupEqualizer() setupEqualizer()
setupPresetStyle() setupPresetStyle()
setupReverberation() // some mobiles throws error here
// setupReverberation()
setupBassBoost() setupBassBoost()
setLoudnessEnhancer() setLoudnessEnhancer()
setupVisualizer() setupVisualizer()
@ -244,12 +245,12 @@ class AudioEffectActivity : AppCompatActivity(), OnSeeBarListener {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
mEqualizer!!.release() mEqualizer?.release()
mPresetReverb!!.release() mPresetReverb?.release()
mBass!!.release() mBass?.release()
loudnessEnhancer!!.release() loudnessEnhancer?.release()
releaseVisualizer() releaseVisualizer()
mPlayer!!.release() mPlayer?.release()
} }
} }

@ -1,7 +1,7 @@
package com.frank.ffmpeg.format; package com.frank.ffmpeg.format;
import android.media.audiofx.Visualizer; import android.media.audiofx.Visualizer;
import android.os.Build; import android.util.Log;
/** /**
* Visualizer of Audio frequency * Visualizer of Audio frequency
@ -12,14 +12,19 @@ public class AudioVisualizer {
private Visualizer visualizer; private Visualizer visualizer;
public void initVisualizer(int audioSession, boolean waveform, boolean fft, Visualizer.OnDataCaptureListener dataCaptureListener) { public void initVisualizer(int audioSession, boolean waveform, boolean fft, Visualizer.OnDataCaptureListener dataCaptureListener) {
visualizer = new Visualizer(audioSession); try {
int captureSize = Visualizer.getCaptureSizeRange()[1]; visualizer = new Visualizer(audioSession);
int captureRate = Visualizer.getMaxCaptureRate() / 2; int captureSize = Visualizer.getCaptureSizeRange()[1];
int captureRate = Visualizer.getMaxCaptureRate() / 2;
visualizer.setCaptureSize(captureSize); visualizer.setCaptureSize(captureSize);
visualizer.setDataCaptureListener(dataCaptureListener, captureRate, waveform, fft); visualizer.setDataCaptureListener(dataCaptureListener, captureRate, waveform, fft);
visualizer.setScalingMode(Visualizer.SCALING_MODE_NORMALIZED); visualizer.setScalingMode(Visualizer.SCALING_MODE_NORMALIZED);
visualizer.setEnabled(true); visualizer.setEnabled(true);
} catch (Exception e) {
Log.e("AudioVisualizer", "initVisualizer error=" + e.toString());
releaseVisualizer();
}
} }
public void releaseVisualizer() { public void releaseVisualizer() {

Loading…
Cancel
Save