Skip to content

Multiple playbacks

Playing many Videos at the same time

Available from v1.1.0.2011003

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 candidate (= 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 a 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.

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:

  • MULTI_PLAYER: play all Playbacks selected by the Selector.
  • SINGLE_PLAYER: play the first available Playback from the list selected by the Selector.
  • NO_PLAYER: do not let the Selector select anything.

NOTE: 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.