Navigation
As described, all Player
implementations accept either a single video or a group of them (through
either List
or Playlist
). When your content includes more than one video, players are able
to navigate between them.
val player: Player = ...
player.set(videoList, play = true)
player.set(videoPlaylist, play = true)
The Navigator object
Internally, navigation is managed by a Navigator
object (see below) that you
can access using Player.navigator
and register listeners if needed.
The navigator will let you navigate through the player content using handy next / previous functions.
// Navigates to the next element, if [hasNext] is true. Does nothing otherwise.
player.navigator.next()
player.navigator.hasNext
// Navigates to the previous element, if [hasPrevious] is true. Does nothing otherwise.
player.navigator.previous()
player.navigator.hasPrevious
// Whether the navigator is navigating from one element to another. Some player implementations
// have transition support so navigating can take time.
player.isNavigating
// Current position and size of content
player.current
player.size
You can also use Navigator.Observer
to receive real-time updates. This functionality is used, for
example, by controls to keep the UI up-to-date:
player.navigator.addObserver(lifecycle, object : Navigator.Observer {
override fun onNavigationStart() { ... }
override fun onNavigationEnd() { ... }
override fun onNavigabilityChanged(hasPrevious: Boolean, hasNext: Boolean) { ... }
})
For coroutine users, the Navigator
also exposes some flows.