Kohii recipes

API

selector - Kohii

Index - Kohii

Add bucket - Kohii

Use case

From v1.1.0.2011003, Kohii adds Playback Selector and Playback Strategy to support multiple playbacks. The Selector is a Single Abstract Method that accepts a collection of candidates (= the Playbacks that can play the media) and returns a collection of Playback that should play the media.

This feature is enabled at Bucket level. Which means that: client can have multiple playbacks in one Bucket by using correct Strategy and Selector. The setup is easy: you can set the Strategy and Selector at the time you add the Bucket.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/1d5b6e6b-50c3-4bc0-b4b9-d2673010418c/kohii_demo_multi_player.gif

Sample code & Explanation

kohii.register(this)
    .addBucket(
        view = recyclerView,
        strategy = Strategy.MULTI_PLAYER,
        selector = { candidates ->
          candidates.take(2)
        }
    )

The code above will: add a new Bucket for the recyclerView, with MULTI_PLAYER Strategy and using a Selector that will select up to 2 Playbacks from the candidates to play. Note that, Strategy and Selector need to be set together to enable the multiple playbacks. If the client uses a Selector that selects many Playbacks, but uses the SINGLE_PLAYER Strategy, it will only play one Playback. The available Strategies are:

Warning

Multiple playbacks comes with a caveat. In Video playback, audio focus is an important aspect. The client needs to not only respect the audio focus given by system, but also to respect the audio focuses among a Video with the others in the same Application. Therefore, when the client enable MULTI_PLAYER Strategy, the library will forcefully mute the audio of all available Playbacks, regardless the number of Playbacks selected by the Selector. Changing to SINGLE_PLAYER or NO_PLAYER Strategy will switch everything back to normal.