-
- All Implemented Interfaces:
-
com.google.android.horologist.media.repository.PlayerRepository,java.io.Closeable,java.lang.AutoCloseable
public final class PlayerRepositoryImpl implements PlayerRepository, Closeable
Repository for the current Media3 Player for a Player Activity.
The current implementation is available as soon as the ListenableFuture to connect to the MediaSession completes.
-
-
Field Summary
Fields Modifier and Type Field Description private final StateFlow<Player>playerprivate final StateFlow<Boolean>connectedprivate final StateFlow<Set<Command>>availableCommandsprivate final StateFlow<PlayerState>currentStateprivate final StateFlow<Media>currentMediaprivate final StateFlow<MediaPosition>mediaPositionprivate final StateFlow<Boolean>shuffleModeEnabledprivate final StateFlow<Float>playbackSpeed
-
Constructor Summary
Constructors Constructor Description PlayerRepositoryImpl()
-
Method Summary
Modifier and Type Method Description final StateFlow<Player>getPlayer()StateFlow<Boolean>getConnected()StateFlow<Set<Command>>getAvailableCommands()StateFlow<PlayerState>getCurrentState()StateFlow<Media>getCurrentMedia()StateFlow<MediaPosition>getMediaPosition()StateFlow<Boolean>getShuffleModeEnabled()final StateFlow<Float>getPlaybackSpeed()final Unitconnect(Player player, Function0<Unit> onClose)Connect this repository to the player including listening to events. Unitclose()Close this repository and release the listener from the player. Unitprepare()Unitplay()Unitplay(Integer mediaIndex)Unitpause()BooleanhasPreviousMedia()UnitskipToPreviousMedia()BooleanhasNextMedia()UnitskipToNextMedia()DurationgetSeekBackIncrement()UnitseekBack()DurationgetSeekForwardIncrement()UnitseekForward()UnitsetShuffleModeEnabled(Boolean shuffleModeEnabled)UnitsetMedia(Media media)This operation will stop the current MediaItem that is playing, if there is one, as per Player.setMediaItem. UnitsetMediaList(List<Media> mediaList)This operation will stop the current MediaItem that is playing, if there is one, as per Player.setMediaItems. UnitaddMedia(Media media)UnitaddMedia(Integer index, Media media)UnitremoveMedia(Integer index)UnitclearMediaList()IntegergetMediaCount()MediagetMediaAt(Integer index)IntegergetCurrentMediaIndex()Unitrelease()final UnitupdatePosition()Update the position to show track progress correctly on screen. final UnitsetPlaybackSpeed(Float speed)-
-
Method Detail
-
getPlayer
final StateFlow<Player> getPlayer()
-
getConnected
StateFlow<Boolean> getConnected()
-
getAvailableCommands
StateFlow<Set<Command>> getAvailableCommands()
-
getCurrentState
StateFlow<PlayerState> getCurrentState()
-
getCurrentMedia
StateFlow<Media> getCurrentMedia()
-
getMediaPosition
StateFlow<MediaPosition> getMediaPosition()
-
getShuffleModeEnabled
StateFlow<Boolean> getShuffleModeEnabled()
-
getPlaybackSpeed
final StateFlow<Float> getPlaybackSpeed()
-
connect
final Unit connect(Player player, Function0<Unit> onClose)
Connect this repository to the player including listening to events.
-
hasPreviousMedia
Boolean hasPreviousMedia()
-
skipToPreviousMedia
Unit skipToPreviousMedia()
-
hasNextMedia
Boolean hasNextMedia()
-
skipToNextMedia
Unit skipToNextMedia()
-
getSeekBackIncrement
Duration getSeekBackIncrement()
-
getSeekForwardIncrement
Duration getSeekForwardIncrement()
-
seekForward
Unit seekForward()
-
setShuffleModeEnabled
Unit setShuffleModeEnabled(Boolean shuffleModeEnabled)
-
setMedia
Unit setMedia(Media media)
This operation will stop the current MediaItem that is playing, if there is one, as per Player.setMediaItem.
-
setMediaList
Unit setMediaList(List<Media> mediaList)
This operation will stop the current MediaItem that is playing, if there is one, as per Player.setMediaItems.
-
removeMedia
Unit removeMedia(Integer index)
-
clearMediaList
Unit clearMediaList()
-
getMediaCount
Integer getMediaCount()
-
getMediaAt
Media getMediaAt(Integer index)
-
getCurrentMediaIndex
Integer getCurrentMediaIndex()
-
updatePosition
final Unit updatePosition()
Update the position to show track progress correctly on screen. Updating roughly once a second while activity is foregrounded is appropriate.
-
setPlaybackSpeed
final Unit setPlaybackSpeed(Float speed)
-
-
-
-