mitchtabian / Video-Player-RecyclerView

Auto play videos in a RecyclerView with ExoPlayer like YouTube does
160 stars 70 forks source link

When list loaded first video not play #4

Open mrj976 opened 4 years ago

mrj976 commented 4 years ago

Thank you I have problem When list loaded first video not play and when i scroll list first video playing I want when list loaded first video play without scroll list Please help me Thanks

paulocoutinhox commented 3 years ago

Im with the same problem.

How can we play the first video when list loaded?

Thanks.

paulocoutinhox commented 3 years ago

I made a solution:

Inside your RecyclerView class create the method:

fun checkToPlayVideo() {
    if (canScrollVertically(1)) {
        playVideo(false)
    } else {
        playVideo(true)
    }
}

And when you set RecyclerView "items" you need call:

private fun updateList() {
    list?.layoutManager = createLayoutManager()
    list?.setListObjects(listData ?: ArrayList())
    list?.adapter = adapter
    list?.setHasFixedSize(true)

    Handler().postDelayed({
        list?.checkToPlayVideo()
    }, 200)
}

Thanks.