-
- 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<MediaItem>currentMediaItemprivate final StateFlow<MediaItemPosition>mediaItemPositionprivate 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<MediaItem>getCurrentMediaItem()StateFlow<MediaItemPosition>getMediaItemPosition()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 mediaItemIndex)Unitpause()BooleanhasPreviousMediaItem()UnitskipToPreviousMediaItem()BooleanhasNextMediaItem()UnitskipToNextMediaItem()DurationgetSeekBackIncrement()UnitseekBack()DurationgetSeekForwardIncrement()UnitseekForward()UnitsetShuffleModeEnabled(Boolean shuffleModeEnabled)UnitsetMediaItem(MediaItem mediaItem)This operation will stop the current MediaItem that is playing, if there is one, as per Player.setMediaItem. UnitsetMediaItems(List<MediaItem> mediaItems)This operation will stop the current MediaItem that is playing, if there is one, as per Player.setMediaItems. UnitaddMediaItem(MediaItem mediaItem)UnitaddMediaItem(Integer index, MediaItem mediaItem)UnitremoveMediaItem(Integer index)UnitclearMediaItems()IntegergetMediaItemCount()MediaItemgetMediaItemAt(Integer index)IntegergetCurrentMediaItemIndex()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()
-
getCurrentMediaItem
StateFlow<MediaItem> getCurrentMediaItem()
-
getMediaItemPosition
StateFlow<MediaItemPosition> getMediaItemPosition()
-
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.
-
hasPreviousMediaItem
Boolean hasPreviousMediaItem()
-
skipToPreviousMediaItem
Unit skipToPreviousMediaItem()
-
hasNextMediaItem
Boolean hasNextMediaItem()
-
skipToNextMediaItem
Unit skipToNextMediaItem()
-
getSeekBackIncrement
Duration getSeekBackIncrement()
-
getSeekForwardIncrement
Duration getSeekForwardIncrement()
-
seekForward
Unit seekForward()
-
setShuffleModeEnabled
Unit setShuffleModeEnabled(Boolean shuffleModeEnabled)
-
setMediaItem
Unit setMediaItem(MediaItem mediaItem)
This operation will stop the current MediaItem that is playing, if there is one, as per Player.setMediaItem.
-
setMediaItems
Unit setMediaItems(List<MediaItem> mediaItems)
This operation will stop the current MediaItem that is playing, if there is one, as per Player.setMediaItems.
-
addMediaItem
Unit addMediaItem(MediaItem mediaItem)
-
addMediaItem
Unit addMediaItem(Integer index, MediaItem mediaItem)
-
removeMediaItem
Unit removeMediaItem(Integer index)
-
clearMediaItems
Unit clearMediaItems()
-
getMediaItemCount
Integer getMediaItemCount()
-
getMediaItemAt
MediaItem getMediaItemAt(Integer index)
-
getCurrentMediaItemIndex
Integer getCurrentMediaItemIndex()
-
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)
-
-
-
-