Akshay
Akshay

Reputation: 31

How can I show song duration and circular seekbar

Im beginner in Android and I'm create one music app but I need to show song duration and circular seekbar on my app

Upvotes: 0

Views: 1340

Answers (1)

Vipul Chauhan
Vipul Chauhan

Reputation: 219

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

Upvotes: 2

Related Questions