如何使用我的媒体播放器实现均衡器 activity
how to implement the equalizer with my mediaplayer activity
我已经在媒体播放器中创建了我的在线电台。我必须为低音、高音、混响等可变音效设置均衡器,我的媒体播放器在主 Acitvity 中。如何使用我的主 activity?
实现包含均衡器的 activity
我的均衡器只有搜索栏:
public class EqualizerActivity extends AppCompatActivity {
MediaPlayer mediaPlayer;
LinearLayout linear;
SeekBar seekbar;
private Equalizer mEqualizer;
TextView tvequalizer,tvcenfreq,tvmineq,tvmaxeq;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainactivity);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = MediaPlayer.create(this,R.raw.mukilmusic);
setupEqualizerFxAndUI();
mediaPlayer.setLooping(true);
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mediaPlayer) {
// mVisualizer.setEnabled(false);
}
});
mediaPlayer.start();
// tvaudio.setText("Playing audio...");
}
private void setupEqualizerFxAndUI() {
mEqualizer = new Equalizer(0, mediaPlayer.getAudioSessionId());
mEqualizer.setEnabled(true);
linear = (LinearLayout)findViewById(R.id.linear) ;
tvequalizer = (TextView) findViewById(R.id.tvequalizer);
tvequalizer.setText("Equalizer:");
// linear.addView(tvequalizer);
short bands = mEqualizer.getNumberOfBands();
final short minEQLevel = mEqualizer.getBandLevelRange()[0];
final short maxEQLevel = mEqualizer.getBandLevelRange()[1];
for (short i = 0; i < bands; i++) {
final short band = i;
tvcenfreq = (TextView) findViewById(R.id.tvcenfreq);
tvcenfreq.setText((mEqualizer.getCenterFreq(band) / 1000) + " Hz");
// linear.addView(tvcenfreq);
LinearLayout row = new LinearLayout(this);
row.setOrientation(LinearLayout.HORIZONTAL);
tvmineq = new TextView(this);
tvmineq.setText((minEQLevel/ 100) + " db");
// linear.addView(tvmineq);
tvmaxeq = new TextView(this);
tvmaxeq.setText((maxEQLevel/ 100) + " db");
// linear.addView(tvmaxeq);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.weight = 1;
seekbar = new SeekBar(this);
seekbar.setLayoutParams(layoutParams);
seekbar.setMax(maxEQLevel - minEQLevel);
seekbar.setProgress(mEqualizer.getBandLevel(band));
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
mEqualizer.setBandLevel(band, (short) (progress + minEQLevel));
}
public void onStartTrackingTouch(SeekBar seekBar) {}
public void onStopTrackingTouch(SeekBar seekBar) {}
});
row.addView(tvmineq);
row.addView(seekbar);
row.addView(tvmaxeq);
linear.addView(row);
}
}
@Override
protected void onPause() {
super.onPause();
if (isFinishing() && mediaPlayer != null) {
// mVisualizer.release();
mEqualizer.release();
mediaPlayer.release();
mediaPlayer = null;
}
}
Crate an Equalizer
Equalizer equalizer = new Equalizer(0,mediaplayer.getAudioSessionId());
equalizer.setEnabled(true);
equalizer.getNumberOfBands(); //it tells you the number of equalizer in device.
equalizer.getNumberOfPresets();//like Normal Classic,Dance Flat,Folk Heavy Metal,Hip Hop,Jazz, Pop, Rock
Link
Android Visualizer implementation crash
https://developer.android.com/reference/android/media/audiofx/Equalizer.html
http://www.101apps.co.za/articles/perfect-sound-using-the-equalizer-effect-a-tutorial.html
我已经在媒体播放器中创建了我的在线电台。我必须为低音、高音、混响等可变音效设置均衡器,我的媒体播放器在主 Acitvity 中。如何使用我的主 activity?
实现包含均衡器的 activity我的均衡器只有搜索栏:
public class EqualizerActivity extends AppCompatActivity {
MediaPlayer mediaPlayer;
LinearLayout linear;
SeekBar seekbar;
private Equalizer mEqualizer;
TextView tvequalizer,tvcenfreq,tvmineq,tvmaxeq;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainactivity);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = MediaPlayer.create(this,R.raw.mukilmusic);
setupEqualizerFxAndUI();
mediaPlayer.setLooping(true);
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mediaPlayer) {
// mVisualizer.setEnabled(false);
}
});
mediaPlayer.start();
// tvaudio.setText("Playing audio...");
}
private void setupEqualizerFxAndUI() {
mEqualizer = new Equalizer(0, mediaPlayer.getAudioSessionId());
mEqualizer.setEnabled(true);
linear = (LinearLayout)findViewById(R.id.linear) ;
tvequalizer = (TextView) findViewById(R.id.tvequalizer);
tvequalizer.setText("Equalizer:");
// linear.addView(tvequalizer);
short bands = mEqualizer.getNumberOfBands();
final short minEQLevel = mEqualizer.getBandLevelRange()[0];
final short maxEQLevel = mEqualizer.getBandLevelRange()[1];
for (short i = 0; i < bands; i++) {
final short band = i;
tvcenfreq = (TextView) findViewById(R.id.tvcenfreq);
tvcenfreq.setText((mEqualizer.getCenterFreq(band) / 1000) + " Hz");
// linear.addView(tvcenfreq);
LinearLayout row = new LinearLayout(this);
row.setOrientation(LinearLayout.HORIZONTAL);
tvmineq = new TextView(this);
tvmineq.setText((minEQLevel/ 100) + " db");
// linear.addView(tvmineq);
tvmaxeq = new TextView(this);
tvmaxeq.setText((maxEQLevel/ 100) + " db");
// linear.addView(tvmaxeq);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.weight = 1;
seekbar = new SeekBar(this);
seekbar.setLayoutParams(layoutParams);
seekbar.setMax(maxEQLevel - minEQLevel);
seekbar.setProgress(mEqualizer.getBandLevel(band));
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
mEqualizer.setBandLevel(band, (short) (progress + minEQLevel));
}
public void onStartTrackingTouch(SeekBar seekBar) {}
public void onStopTrackingTouch(SeekBar seekBar) {}
});
row.addView(tvmineq);
row.addView(seekbar);
row.addView(tvmaxeq);
linear.addView(row);
}
}
@Override
protected void onPause() {
super.onPause();
if (isFinishing() && mediaPlayer != null) {
// mVisualizer.release();
mEqualizer.release();
mediaPlayer.release();
mediaPlayer = null;
}
}
Crate an Equalizer
Equalizer equalizer = new Equalizer(0,mediaplayer.getAudioSessionId());
equalizer.setEnabled(true);
equalizer.getNumberOfBands(); //it tells you the number of equalizer in device.
equalizer.getNumberOfPresets();//like Normal Classic,Dance Flat,Folk Heavy Metal,Hip Hop,Jazz, Pop, Rock
Link
Android Visualizer implementation crash https://developer.android.com/reference/android/media/audiofx/Equalizer.html http://www.101apps.co.za/articles/perfect-sound-using-the-equalizer-effect-a-tutorial.html