eneim / kohii

Android Video Playback made easy.
https://eneim.github.io/kohii/
Apache License 2.0
378 stars 51 forks source link

Is it possible to use this with a FragmentStateAdapter? #116

Open missphyrgames opened 3 years ago

missphyrgames commented 3 years ago

Hi eneim,

Thank you for this great library, however, I'm having trouble using this with a FragmentStateAdapter and making sure I'm following best practices. Would you be able to guide me on how to achieve this?

eneim commented 3 years ago

@missphyrgames Do you mean using it in ViewPager with FragmentStateAdapter? If it is, you can find some existing sample here: https://github.com/eneim/kohii/tree/dev-v1/kohii-sample/src/main/java/kohii/v1/sample/ui/pagers, please also clarify your current attempt and what doesn't work so I can investigate.

missphyrgames commented 3 years ago

@eneim Thank you so much for the quick reply! I'll have another go at this! Also, thank you for the link.

If you don't mind would you please also answer a few more questions I have:

  1. Is it more efficient for allowing kohii to create a playerview from the pool (using a view container in the layout file) or is it better to have a playerview component in the layout file for each page in the viewpager?
  2. If I go with the first option in the question above, is there a way to override the default implementation of the playerview you instantiate? I would like to change the resize_mode to be fixed_height or zoom
  3. In the documentation I see that you mention that if there is no tag present in the setup of kohii, the video should restart from the beginning when you return to the page after scrolling, however this is not the case for me. I'm using the tiktok sample app you have provided.
missphyrgames commented 3 years ago

This is what the setup looks like:

kohii.setUp(videoFile) {
      threshold = 0.5F
      preload = true
      repeatMode = Common.REPEAT_MODE_ALL
}.bind(holder.binding.playerView) {
      it.addStateListener(holder)
}
eneim commented 3 years ago

@missphyrgames Sorry for the late reply

Is it more efficient for allowing kohii to create a playerview from the pool (using a view container in the layout file) or is it better to have a playerview component in the layout file for each page in the viewpager?

Depends on how you define your efficiency. Using the PlayerView pool = less memory footprint, but also less user-friendly (it needs to warm up the PlayerView for new Video after you change it, etc). So you can have some benchmark and decide on your own.

If I go with the first option in the question above, is there a way to override the default implementation of the playerview you instantiate? I would like to change the resize_mode to be fixed_height or zoom

The Pool can be configured by providing a custom RendererProvider. You can follow this class to build your own PlayerViewProvider: https://github.com/eneim/kohii/blob/dev-v1/kohii-exoplayer/src/main/java/kohii/v1/exoplayer/PlayerViewProvider.kt, and use this builder https://github.com/eneim/kohii/blob/6f598b80288512067b1e9c1c95ec0d13697d59ee/kohii-exoplayer/src/main/java/kohii/v1/exoplayer/Kohii.kt#L170 to create a Kohii instance using your custom PlayerViewProvider.

In the documentation I see that you mention that if there is no tag present in the setup of kohii, the video should restart from the beginning when you return to the page after scrolling, however this is not the case for me. I'm using the tiktok sample app you have provided.

I see. The document is the expected behavior, so maybe it is an issue. I will double check :-?.