Kohii: what to come
It's been a while since I shared about Kohii in DroidKaigi 2019 with a series of posts follows (Part 1, Part 2, Part 3, Part 4): the background, the problem to solve and an abstract approach with a working demo. Since then, I spend a lot of time improving the architecture and implementing the ideas, hoping to bring Kohii to live as soon as possible.
Today, I would like to say that the overall design is completed, and this post will try to draw a general roadmap about what will come, what Kohii can do to help you.
1. What Kohii can do
Mission of Kohii is to help adding Video playback to Android app as easy as possible. It is not limited to Video playback in RecyclerView or any scrolling container as I always discuss about, but it is about Video playback in general.
Let's take a look at Kohii in practice. These lines are what you need to integrate auto Video play/pause to RecyclerView:
// Step 1: In Fragment/Activity: initialize Kohii and attach the main container. // In this case, we care about the RecyclerView only. val kohii = Kohii[this] // get an instance to pass around. kohii.register(this) // return a 'PlaybackManager' object .attach(recyclerView) // add the RecyclerView to the PlaybackManager // Step 2: Setup ViewHolder using ``kohii`` instance. kohii.setUp(videoUrl).bind(playerView)
With the setup above, you get:
- Video will be started/paused automatically according to user scroll. The top-most Video whose visible area is at least 65% of its full size will be picked to play, others will be paused.
- During configuration changes, Videos keep their state without any reloading. The image may be flashed as the Surface is replaced, but the audio keeps playing.
- The setup works out of the box for RecyclerView, NestedScrollView. For special ViewGroups like ViewPager, ViewPager2, the setup will be a bit more complicated, but still doable. Setup for more complicated use cases will be discussed in advance topics.
Under the hood, Kohii takes care of memory management, resource recycling and so on. You should not need to worry about memory leak and performance. At heart, I believe Kohii's performance is outstanding comparing to any other approaches.
2. The feature roadmap
In the first final release, I will finalize the main features below and try to build up a multiple use cases demo. The unchecked means it is not ready yet at the moment of this post, but I will keep updating it here as well as in the Github repo.
- Simple syntax to start binding a Video to a ViewGroup (PlayerView or a ViewGroup that will contain a PlayerView), using Url, Uri or specific Media object.
- Automatically update the playbacks in RecyclerView, NestedScrollView or general ViewGroup.
- Automatically update the playbacks in ViewPager, ViewPager2.
- Callbacks for Kohii components status.
- Callbacks for playback status.
(Nice to have) Opinionated callbacks that tell client when it should show/hide thumbnail.
Handle configuration change
- Retain playback on configuration changes.
Manual control over Playbacks
- Allow client to have full control over Playbacks: client can start/pause any Playback without the control of system/Kohii.
- Allow client to have half-manual control over Playbacks: client can start/pause any Playback on demand, but Kohii can also start/pause the Playback regarding some conditions.
- Global control: simple method to pause/resume everything. The resume behavior follow each Playback's config.
- Flexible VolumeInfo update mechanism: allow to change VolumeInfo for individual Video or all Videos in the same parent.
ExoPlayer related implementations
- First-class support for playback using ExoPlayer/PlayerView.
- Cached playback using ExoPlayer cache mechanism.
- Offline/downloaded playback using ExoPlayer download mechanism.
- Base abstraction.
- Default implementation for ExoPlayer.
- (Nice to have) Experiment implementation for YouTube Videos using YouTube Player API.
- (Nice to have) Experiment implementation for YouTube Videos using OSS playback library.
- (Nice to have) Experiment implementation for AndroidX Media 2.
(Nice to have) Experiment implementation for Platform MediaPlayer/VideoViewJust drop this.
- Flag/Callback to enable/disable automatic playback. Useful to trigger the feature on demand (eg: due to Network quality changes).
MemoryModesetting, allows client to control how Videos will be kept when it is not playing. For example in HIGH MemoryMode, many Videos can keep resource at the same time, so the playback will be really smooth, but in LOW MemoryMode, any paused Video will be released to save resource.
- Ads support with Mopub, IMA.
- Basic RecyclerView sample, no nesting.
- Basic NestedScrollView sample, no nesting.
- RecyclerView with NestedScrollView nested in a ViewHolder.
- RecyclerView with RecyclerView nested in a ViewHolder.
- NestedScrollView with a RecyclerView nested inside.
- RecyclerView with user interaction (eg: Click).
- NestedScrollView with user interaction (eg: Click).
- ViewPager where pages are PlayerViews or FrameLayouts.
ViewPager where pages are RecyclerViews with Videos.(It is recommended to use Fragment with RecyclerView inside ViewPager instead)
- ViewPager where pages are Fragments contain PlayerViews or FrameLayout.
- ViewPager where pages are Fragments contain RecyclerView with Videos.
- ViewPager2 where pages are PlayerViews or FrameLayouts.
ViewPager2 where pages are RecyclerViews with Videos.(It is recommended to use Fragment with RecyclerView inside ViewPager instead)
- ViewPager2 where pages are Fragments contain PlayerViews or FrameLayout.
- ViewPager2 where pages are Fragments contain RecyclerView with Videos.
- Multiple Fragments where each contains RecyclerView or ViewPager with Videos.
- Sample to mimic Facebook.
- YouTube sample using Android Player SDK (the Official SDK).
- YouTube sample using PierfrancescoSoffritti/android-youtube-player.
Current implementation is updated on Kohii github repo. Once the roadmap above is cleared, I will publish a Beta release on Github, which will follow with RC (Release Candidate) and then Final release.
Below is something I want to archive, but the design is not yet done:
Background Playback support
- Allow configuration to enable/disable background Playback. The config would allow to setup: flag to turn the feature on/off, necessary information for the foreground notification (eg Bitmap for the Notification large image).
- Allow the Playback to keep playing after closing the App on-demand.
- Allow the Playback to keep playing when: the Playback is deselected from the Manager, but no newer Playback is selected.
- Store PlaybackInfo to pages + local DB to optimize/reduce in-memory cache.
It's worth noting that, Kohii has quite complicated design and require a lot of time to build. I may need to drop some, or delay some features in order to make a stable release.
3. Final words
That is, the very first official roadmap for
Kohii: Android Video Playback made easy. I have been trying to address the challenge in Video playback for quite a long time. Hope that what I put in Kohii can help many more developers having the same problems.
Last but not least: my sponsors page is online. Any support is truly appreciated from my heart <3.