Search code examples
androidxmlandroid-mediaplayerseekbarandroid-seekbar

How to set MAX vaalue of a SeekBar in XML file?


I am making a Music Playe app and I am using a custom Circular seekbar made by And it's max value is defined in the XML file

        <SeekBar
        android:id="@+id/musicSeekBar"
        android:layout_width="220dp"
        android:layout_height="220dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="18dp"
        android:padding="16dp"
        app:max="100"/>

Now, I want to assign the max value of the SeekBar to the total duration of the media file , but the function Seekbar.setMax(int) doesn't work. How can I do this?


Solution

  • You can instead calculate the progress based on the duration and set that progress. Let the max be 100 and so we can get the progress percentage by getting

    x= (current_played_time)*100/ (total_time) 
    

    and

    seekbar.setProgress(x);