Padding found in the Default time bar and android of exoplayer

Viewed 174

Here is the implementation of the Default time bar where I have customized to add segments

XML

 <com.sampleapp.androidapp.kotlin.util.exoplayer.SampleAppDefaultTimeBar
                android:id="@id/exo_progress"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:bar_height="2dp"
                app:buffered_color="@color/gb_seek_bar_buffer"
                app:layout_constraintStart_toStartOf="parent"
                app:played_color="@color/gb_seek_bar_played"
                app:scrubber_color="@color/gb_seek_bar_played"
                app:unplayed_color="@color/gb_seek_bar_unplayed" />

Code

class SampleAppDefaultTimeBar : DefaultTimeBar {

    companion object {
        const val DIVIDER_WIDTH = 5F
        const val PROGRESS_LEFT_RIGHT_PADDING = 32F
    }

    // List of points for creating sections
    var indicatorPositions: List<Float> = arrayListOf()
    var enableSegmentsForPlayer: Boolean = false
    //var indicatorPositions: List<Float> = listOf(0.13F, 0.34F, 0.57F, 0.85F, 0.92F)

    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context,
        attrs, defStyle)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)

    private val paintIndicator = Paint().apply {
        isAntiAlias = true
        style = Paint.Style.FILL
        color = ContextCompat.getColor(context, R.color.black)
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        drawProgressDivider(canvas)
    }

    private fun drawProgressDivider(canvas: Canvas) {
        if(enableSegmentsForPlayer){
            // Only if the segments are enabled - Draw the segments
            indicatorPositions.forEach {
                val barPositionCenter = it * width()
                val barPositionLeft = barPositionCenter - DIVIDER_WIDTH
                val barPositionRight = barPositionCenter + DIVIDER_WIDTH

                drawOnCanvas(canvas, paintIndicator, barPositionLeft, barPositionRight)
            }
        }
    }

    private fun width(): Float {
        return measuredWidth.toFloat()
    }

    private fun drawOnCanvas(canvas: Canvas, paint:Paint, progressLeft: Float, progressRight: Float) {
        //val barTop = (measuredHeight - barHeight) / 2
        //val barBottom = (measuredHeight + barHeight) / 2
        val progressTop = height / 1.8 - minimumHeight / 2
        val progressBottom = progressTop / 1.3 + minimumHeight / 2

        val barRect = RectF(progressLeft, progressTop.toFloat(),
            progressRight, progressBottom.toFloat())
        canvas.drawRoundRect(barRect, 50F, 50F, paint)
    }

}

Output

enter image description here

  • As seen in the image above there is padding at the beginning and end of the bar if the points are found to be at the very begining.
  • It's the space for the thumb
  • How to remove that Padding
0 Answers
Related