One of the normal use case in Video player Application is to have a controller so that user can seek, pause or resume the Video on demand. This tutorial guides you how to do that using Kohii.
The application we build will:
https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a520b9be-b4a2-414a-9d5b-f7c110a0320f/kohii_tut_102_1.webm
You should complete the previous tutorial first.
This tutorial will start from where we finish in:
Simple Video player using Kohii
Also, we only need to have one step below:
To do so, we need to use the controller
parameter in the setUp
lambda:
kohii.setUp(videoUrl) {
tag = videoUrl
+ controller = object : Controller {
+ override fun kohiiCanStart(): Boolean = true
+ override fun kohiiCanPause(): Boolean = true
+
+ override fun setupRenderer(
+ playback: Playback,
+ renderer: Any?
+ ) {
+ if (renderer is PlayerView) {
+ renderer.useController = true
+ renderer.setControlDispatcher(kohii.createControlDispatcher(playback))
+ }
+ }
+
+ override fun teardownRenderer(
+ playback: Playback,
+ renderer: Any?
+ ) {
+ if (renderer is PlayerView) {
+ renderer.useController = false
+ renderer.setControlDispatcher(null)
+ }
+ }
+ }
}
.bind(playerView)
}
Explanations:
Controller
object is an interface that if you set it up, Kohii will automatically know that the Video wants to have manual control.kohiiCanStart()
returns false, the Video will not start automatically when your App launches. It it returns true, the Video will start automatically, but once user pauses it manually, it will only resume when the user resumes it manually. If kohiiCanPause()
returns false, the Video will keep it playing state regardless of if it is visible enough or it is hidden.