-
- All Implemented Interfaces:
-
org.readium.r2.navigator.Navigator
public final class MediaNavigator implements NavigatorAn audiobook navigator to connect to a MediaSession from Jetpack Media2.
Use create to get an instance for a given publication, and build a session from it with the session method. Apps are responsible for attaching this session to a service able to expose it.
You can build a MediaNavigator upon any Media2 SessionPlayer implementation providing create with it. If you don't, ExoPlayer will be used, without cache. You can build your own SessionPlayer based on ExoPlayer using ExoPlayerDataSource.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classMediaNavigator.Configurationpublic final classMediaNavigator.Playbackpublic classMediaNavigator.Exceptionpublic classMediaNavigator.Companion
-
Field Summary
Fields Modifier and Type Field Description private final StateFlow<Locator>currentLocatorprivate final StateFlow<MediaNavigator.Playback>playbackprivate final Publicationpublicationprivate final LocatorcurrentLocation
-
Method Summary
Modifier and Type Method Description StateFlow<Locator>getCurrentLocator()final StateFlow<MediaNavigator.Playback>getPlayback()Indicates the navigator current state. PublicationgetPublication()final Try<Unit, MediaNavigator.Exception>setPlaybackRate(Double rate)Sets the speed of the media playback. final Try<Unit, MediaNavigator.Exception>play()Resumes or start the playback at the current location. final Try<Unit, MediaNavigator.Exception>pause()Pauses the playback. final Try<Unit, MediaNavigator.Exception>seek(Integer index, Duration position)Seeks to the given time at the given resource. final Try<Unit, MediaNavigator.Exception>go(Locator locator)Seeks to the given locator. final Try<Unit, MediaNavigator.Exception>go(Link link)Seeks to the beginning of the given link. Booleango(Locator locator, Boolean animated, Function0<Unit> completion)Booleango(Link link, Boolean animated, Function0<Unit> completion)final Try<Unit, MediaNavigator.Exception>goForward()Skips to a little amount of time later. BooleangoForward(Boolean animated, Function0<Unit> completion)final Try<Unit, MediaNavigator.Exception>goBackward()Skips to a little amount of time before. BooleangoBackward(Boolean animated, Function0<Unit> completion)final Unitclose()Stops the playback. final MediaSessionsession(Context context, PendingIntent activityIntent, String id)Builds a MediaSession for this navigator. -
-
Method Detail
-
getCurrentLocator
StateFlow<Locator> getCurrentLocator()
-
getPlayback
final StateFlow<MediaNavigator.Playback> getPlayback()
Indicates the navigator current state.
-
getPublication
Publication getPublication()
-
setPlaybackRate
final Try<Unit, MediaNavigator.Exception> setPlaybackRate(Double rate)
Sets the speed of the media playback.
Normal speed is 1.0 and 0.0 is incorrect.
-
play
final Try<Unit, MediaNavigator.Exception> play()
Resumes or start the playback at the current location.
-
pause
final Try<Unit, MediaNavigator.Exception> pause()
Pauses the playback.
-
seek
final Try<Unit, MediaNavigator.Exception> seek(Integer index, Duration position)
Seeks to the given time at the given resource.
-
go
final Try<Unit, MediaNavigator.Exception> go(Locator locator)
Seeks to the given locator.
-
go
final Try<Unit, MediaNavigator.Exception> go(Link link)
Seeks to the beginning of the given link.
-
goForward
final Try<Unit, MediaNavigator.Exception> goForward()
Skips to a little amount of time later.
-
goBackward
final Try<Unit, MediaNavigator.Exception> goBackward()
Skips to a little amount of time before.
-
goBackward
Boolean goBackward(Boolean animated, Function0<Unit> completion)
-
close
final Unit close()
Stops the playback.
Compared to pause, the navigator may clear its state in whatever way is appropriate. For example, recovering a player's resources.
-
session
final MediaSession session(Context context, PendingIntent activityIntent, String id)
Builds a MediaSession for this navigator.
-
-
-
-