|
@@ -5,15 +5,11 @@ import android.content.res.TypedArray;
|
|
|
import android.graphics.Canvas;
|
|
|
import android.graphics.Color;
|
|
|
import android.graphics.Paint;
|
|
|
-import android.graphics.Path;
|
|
|
-import android.graphics.RectF;
|
|
|
import android.media.MediaPlayer;
|
|
|
import android.media.audiofx.Visualizer;
|
|
|
import android.util.AttributeSet;
|
|
|
-import android.util.Log;
|
|
|
import android.view.View;
|
|
|
|
|
|
-import com.cooleshow.base.utils.LOG;
|
|
|
import com.cooleshow.base.utils.SizeUtils;
|
|
|
import com.cooleshow.musicmerge.R;
|
|
|
|
|
@@ -149,16 +145,20 @@ public class MusicFrequencyView extends View {
|
|
|
* @param mediaPlayer
|
|
|
*/
|
|
|
public void setMediaPlayer(final MediaPlayer mediaPlayer) {
|
|
|
- if (visualizer == null) {
|
|
|
- visualizer = new Visualizer(mediaPlayer.getAudioSessionId());
|
|
|
-
|
|
|
- int captureSize = Visualizer.getCaptureSizeRange()[1];
|
|
|
- int captureRate = Visualizer.getMaxCaptureRate() * 3 / 4;
|
|
|
- // 3:设置参数
|
|
|
- visualizer.setCaptureSize(captureSize);
|
|
|
- visualizer.setDataCaptureListener(dataCaptureListener, captureRate, true, true);
|
|
|
- visualizer.setScalingMode(Visualizer.SCALING_MODE_NORMALIZED);
|
|
|
- visualizer.setEnabled(true);
|
|
|
+ try{
|
|
|
+ if (visualizer == null) {
|
|
|
+ visualizer = new Visualizer(mediaPlayer.getAudioSessionId());
|
|
|
+
|
|
|
+ int captureSize = Visualizer.getCaptureSizeRange()[1];
|
|
|
+ int captureRate = Visualizer.getMaxCaptureRate() * 3 / 4;
|
|
|
+ // 3:设置参数
|
|
|
+ visualizer.setCaptureSize(captureSize);
|
|
|
+ visualizer.setDataCaptureListener(dataCaptureListener, captureRate, true, true);
|
|
|
+ visualizer.setScalingMode(Visualizer.SCALING_MODE_NORMALIZED);
|
|
|
+ visualizer.setEnabled(true);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|