我是Android的初学者,我正在创建一个音乐应用,但我需要在应用上显示歌曲时长和圆形搜索栏
I have used the circular seekbar please see the example....
You have to implement this in your Gradle dependencies
implementation 'me.tankery.lib:circularSeekBar:1.1.7'
Then implement it in your xml try it in your own...
<me.tankery.lib.circularseekbar.CircularSeekBar
android:id="@+id/circularSeekBar"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:cs_circle_color="#0000ff"
app:cs_circle_progress_color="#ff0000"
app:cs_circle_stroke_width="4dp"
app:cs_pointer_color="#ff0000"
app:cs_pointer_stroke_width="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
In your Activity
CircularSeekBar seekBar=findViewById(R.id.circularSeekbar);
For setting the seekbar with media player...put the setProgress code in handler to update the seekbar every second
seekBar.setMax(mediaPlayer.getDuration());
seekBar.setProgress(mediaPlayer.getCurrentPosition());
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, float
progress, boolean fromUser) {
int h = Math.round(progress);
//In the above line we are converting the float value into int because
// media player required int value and seekbar library gives progress in float
if (mediaPlayer != null && fromUser) {
mediaPlayer.seekTo(h);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
I am not providing image but it is working fine
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.