kohii icon indicating copy to clipboard operation
kohii copied to clipboard

controller not working without tag in Binder.Option?

Open nirazv opened this issue 4 years ago • 5 comments

I implemented kohii with ViewPager2 but when using tag in Binder.Option its save the current track position of every video which I don't want because of memory limitation. Hence i removed the tag from Binder.Option

When I removed the tag, the controller is also not going to work?

How I can prevent to store the current track position/seek from videoplayer, however the controller should work?

Heres my code with tag and controller

kohii.setUp(url) {
                preload = true
                artworkHintListener = this@VideoViewHolder
                repeatMode = Common.REPEAT_MODE_ONE
                controller = object : Playback.Controller {
                override fun kohiiCanPause(): Boolean = true

                override fun kohiiCanStart(): Boolean = true

                override fun setupRenderer(playback: Playback, renderer: Any?) {
                    itemView.playerContainer.setOnClickListener {
                        val playable = playback.playable?: return@setOnClickListener
                        if (playable.isPlaying()) playback.manager.pause(playable)
                        else playback.manager.play(playable)

                    }
                }

                override fun teardownRenderer(playback: Playback, renderer: Any?) {
                    itemView.playerContainer.setOnClickListener(null)
                }
            }
        }.bind(playerView)

nirazv avatar Sep 25 '20 18:09 nirazv

Sadly almost all advance usage of Kohii requires the tag. I'm working on an update that will optionally purge the cache of the Videos when its Manager is destroyed (or is transited to the state of your choice). Right now, what you can do is to manually reset the Playable at the expected timing.

eneim avatar Sep 26 '20 10:09 eneim

How to reset Player while using kohii and how much it will take to release the new update?

nirazv avatar Sep 26 '20 14:09 nirazv

When you setup a Video, there is a callback to give you the Playback instance. (kohii.setUp(video).bind(container) { playback -> /* do something */ }). You can save this playback and when you need to reset it, call playback.playable?.onReset().

The change to support this is not trivial so you can expect a month or so. I will update the status of better work-around in this issue.

eneim avatar Sep 28 '20 23:09 eneim

its working fine but the play/pause state is not resetting?

Example - if i tap to pause player the video is paused and i scroll to next video its fine(reset) but when i came back to the prev video the state (pause) still remains , How can i reset Play/Pause state also?

nirazv avatar Oct 02 '20 09:10 nirazv

@nirazv It is rather a complicated use case. Originally my thought when designing this feature: if the user manually pauses a Video, it should be the user to resume that video. It is kinda the answer to the question who wants to do what.

I understand it is reasonable to enable the control flow so that when the user scrolls the Video back, it resumes.

Now about designing this: because any scroll can trigger a refresh. So we need to understand the state that a Video is paused, then it is scrolled out of Viewport, and then scrolled back. (Note that, if the Video is paused manually, then after a small scroll happen, it is still in the Viewport enough to be selected, we should never resume the Video. Otherwise the Video will never be manually stoppable). One of the way is to keep a counter/toggle inside the Playback that tells if it is selected or not. To do this, I need to ensure it doesn't affect other existing part.

Just to tell you how I thought about this requirement. Of course if you have another idea I will be happy to hear. But a quick conclusion is that making this feature will take some time. I'm working on this, but may not be there soon enough if you are in hurry.

eneim avatar Oct 19 '20 07:10 eneim