public void setActive(boolean active) { this.active = active; Visualizer visualizer = getVizualiser(); if (visualizer == null) { return; } int captureRate = Math.min(PREFERRED_CAPTURE_RATE_MILLIHERTZ, Visualizer.getMaxCaptureRate()); if (active) { visualizer.setDataCaptureListener( new Visualizer.OnDataCaptureListener() { @Override public void onWaveFormDataCapture( Visualizer visualizer, byte[] waveform, int samplingRate) { updateVisualizer(waveform); } @Override public void onFftDataCapture(Visualizer visualizer, byte[] fft, int samplingRate) {} }, captureRate, true, false); } else { visualizer.setDataCaptureListener(null, captureRate, false, false); } visualizer.setEnabled(active); invalidate(); }
public EqualizerController(View rootView, Context context) { mView = rootView; mContext = context; mPlayer = MediaPlayer.create(context, R.raw.testmp3); setupVisualizerUI(); mEqualizer = new Equalizer(0, mPlayer.getAudioSessionId()); // mEqualizer = new Equalizer(0, 0); mNumFrequencyBands = mEqualizer.getNumberOfBands(); mLowerBandLevel = mEqualizer.getBandLevelRange()[0]; mUpperBandLevel = mEqualizer.getBandLevelRange()[1]; mEqualizer.setEnabled(true); setupEqualizerUI(); mVisualizer.setEnabled(true); // When the stream ends, we don't need to collect any more data. We // don't do this in // setupVisualizerFxAndUI because we likely want to have more, // non-Visualizer related code // in this callback. mPlayer.setOnCompletionListener( new MediaPlayer.OnCompletionListener() { public void onCompletion(MediaPlayer mediaPlayer) { mVisualizer.setEnabled(false); } }); mPlayer.start(); }
/** * Links the visualizer to a player * * @param player - MediaPlayer instance to link to */ public void link(MediaPlayer player) { if (player == null) { throw new NullPointerException("Cannot link to null MediaPlayer"); } // Create the Visualizer object and attach it to our media player. mVisualizer = new Visualizer(player.getAudioSessionId()); mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]); // Pass through Visualizer data to VisualizerView Visualizer.OnDataCaptureListener captureListener = new Visualizer.OnDataCaptureListener() { @Override public void onWaveFormDataCapture( Visualizer visualizer, byte[] bytes, int samplingRate) { updateVisualizer(bytes); } @Override public void onFftDataCapture(Visualizer visualizer, byte[] bytes, int samplingRate) { updateVisualizerFFT(bytes); } }; mVisualizer.setDataCaptureListener( captureListener, Visualizer.getMaxCaptureRate() / 2, true, true); // Enabled Visualizer and disable when we're done with the stream mVisualizer.setEnabled(true); player.setOnCompletionListener( new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mediaPlayer) { mVisualizer.setEnabled(false); } }); }
public void onDetach() { mVisualizer.setEnabled(false); mPlayer.stop(); }
public void onPause() { mVisualizer.setEnabled(false); mPlayer.pause(); }