MediaPlayer和Seekbar
<SeekBar
android:id="@+id/voice_progress"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:progressTint="#22C580"
android:thumbTint="#22C580"
android:maxHeight="2dip"
android:minHeight="2dip"
android:paddingLeft="0dip"
android:paddingRight="0dip"/>
thumbTint
progressTint
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
mMediaPlayer.setDataSource(audioFile.getAbsolutePath());
mMediaPlayer.prepare();
mMediaPlayer.start();
mMediaPlayer.setLooping(false);
mSeekBar.setMax(mMediaPlayer.getDuration());
int currentSecond = mMediaPlayer.getCurrentPosition();
mSeekBar.setProgress(currentSecond);
实现SeekBar.OnSeekBarChangeListener接口,重写一下三个方法
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(fromUser){
mCurrentTime.setText(NoteUtils.secondToTime(progress/1000)+"/");
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
voiceHandler.removeMessages(UPDATE_SEEKBAR_PROGRESS);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
mMediaPlayer.seekTo(seekBar.getProgress());
if (mMediaPlayer.isPlaying()) {
voiceHandler.removeMessages(UPDATE_SEEKBAR_PROGRESS);
voiceHandler.sendEmptyMessage(UPDATE_SEEKBAR_PROGRESS);
}
}
https://www.cnblogs.com/8023-itxinde/p/5212240.html
|