NewPlayerImpl

class NewPlayerImpl(val app: Application, val playerActivityClass: Class<out Activity>, val repository: MediaRepository, val notificationIcon: IconCompat = IconCompat.createWithResource( app, R.drawable.new_player_tiny_icon ), val rescueStreamFault: suspend (item: String?, mediaItem: MediaItem?, Exception, repository: MediaRepository) -> StreamExceptionResponse = { _, _, _, _ -> NoResponse() }) : NewPlayer

Constructors

Link copied to clipboard
constructor(app: Application, playerActivityClass: Class<out Activity>, repository: MediaRepository, notificationIcon: IconCompat = IconCompat.createWithResource( app, R.drawable.new_player_tiny_icon ), rescueStreamFault: suspend (item: String?, mediaItem: MediaItem?, Exception, repository: MediaRepository) -> StreamExceptionResponse = { _, _, _, _ -> NoResponse() })

Properties

Link copied to clipboard
Link copied to clipboard
open override val bufferedPercentage: Int

Same as ExoPlayer's bufferedPercentage. See Player.getBufferedPercentage

Link copied to clipboard
open override val currentChapters: StateFlow<List<Chapter>>

The chapters which are available for the currently playing stream. If the current stream has no chapters the list will be empty.

Link copied to clipboard
open override val currentlyAvailableTracks: StateFlow<List<StreamTrack>>

All the tracks that the current item provides. The list contains the tracks of all available stream.

Link copied to clipboard
open override val currentlyPlaying: StateFlow<MediaItem?>

The currently playing MediaItem. If null no MediaItem is playing.

Link copied to clipboard

The index into the playlist. It points to the currently playing MediaItem.

Link copied to clipboard
open override val currentlyPlayingTracks: StateFlow<List<StreamTrack>>

The tracks that are currently reproduced by ExoPlayer

Link copied to clipboard
open override var currentPosition: Long

Same as ExoPlayer's currentPosition. See Player.getCurrentPosition

Link copied to clipboard

Overrides the preferredStreamLanguages and picks one specific language This value then only works for the current stream. If the stream changes this value switches back to null, and the preferredStreamLanguages are used for stream selection. This is used to pick one specific stream.

Link copied to clipboard
open override val duration: Long

Same as ExoPlayer's duration. See Player.getDuration

Link copied to clipboard
open override val errorFlow: SharedFlow<Exception>

This will emit errors that can not be recovered. The collector should not try to handle the errors but instead directly forward it to the central exception management.

Link copied to clipboard
open override val exoPlayer: StateFlow<ExoPlayer?>

The exoPlayer NewPlayer uses. Since NewPlayer might kill its exoplayer depending on the playback state, the player itself is wrapped in a StateFlow. This way the NewPlayerUI can be notified of a new ExoPlayer being created once the playback state switches away from IDLE.

Link copied to clipboard
open override var fastSeekAmountSec: Int

Amount of seconds that should be skipped on a fast seek action.

Link copied to clipboard
var mutableErrorFlow: MutableSharedFlow<Exception>
Link copied to clipboard
open override val notificationIcon: IconCompat

The Icon that should be shown in the media notification.

Link copied to clipboard
open override val onExoPlayerEvent: SharedFlow<Pair<Player, Player.Events>>
Link copied to clipboard
open override var playBackMode: MutableStateFlow<PlayMode>
Link copied to clipboard
open override val playerActivityClass: Class<out Activity>

The class of the activity that holds the NewPlayerUI.

Link copied to clipboard
open override val playlist: StateFlow<List<MediaItem>>

Represents the current playlist of ExoPlayer. It is derived from ExoPlayer's Player.getCurrentTimeline, and its updated on a timeline change.

Link copied to clipboard
open override var playWhenReady: Boolean

Same as ExoPlayer's playWhenReady. See Player.setPlayWhenReady

Link copied to clipboard

Must be in IETF-BCP-47 format

Link copied to clipboard
open override var repeatMode: RepeatMode

Same as ExoPlayer's repeatMode. See Player.getRepeatMode However, ExoPlayer's repeatMode ist based on an integer, while NewPayer defines it as an enum class.

Link copied to clipboard
open override val repository: MediaRepository

The media repository from which media data is pulled from. This has to be provided by the user.

Link copied to clipboard
open override val rescueStreamFault: suspend (item: String?, mediaItem: MediaItem?, Exception, repository: MediaRepository) -> StreamExceptionResponse

This callback allows to recover from errors that happened during stream playback. When this callback is called the user has a chance to recover from that error. By returning a StreamExceptionResponse the user can decide how NewPlayer should continue. The default implementation by NewPlayerImpl will always return NoResponse. This will cause the exception to be directly forwarded to errorFlow.

Link copied to clipboard
open override var shuffle: Boolean

Same as ExoPlayer's shuffle. See Player.getShuffleModeEnabled

Functions

Link copied to clipboard
open override fun addToPlaylist(item: String)

Adds a new item to the playlist.

Link copied to clipboard
open override fun getItemFromMediaItem(mediaItem: MediaItem): String

Returns the Item corresponding to the MediaItem Please keep int mind that only MediaItem re supported that were created by NewPlayer itself. Otherwise the corresponding item can not be found and the function throws a NewPlayerException.

Link copied to clipboard
open override fun movePlaylistItem(fromIndex: Int, toIndex: Int)

Same as ExoPlayer's movePlaylistItem. See Player.moveMediaItem

Link copied to clipboard
fun onPlayBackError(exception: Exception)
Link copied to clipboard
open override fun pause()

Same as ExoPlayer's Player.pause

Link copied to clipboard
open override fun play()

Same as ExoPlayer's Player.play.

Link copied to clipboard
open override fun playStream(item: String, playMode: PlayMode)

Starts playing a new item. This function will clear the playlist, and start with a new playlist that only contains item.

Link copied to clipboard
open override fun prepare()

Same as ExoPlayer's Player.prepare.

Link copied to clipboard
open override fun release()

Same as ExoPlayer's release. See Player.release In addition to releasing the /** @hide */ internal ExoPlayer, NewPlayer will also clean up other things that do not need to exist while NewPlayer is in IDLE mode. This includes the ExoPlayer instance itself.

Link copied to clipboard
open override fun removePlaylistItem(uniqueId: Long)

Same as ExoPlayer's removePlaylistItem. See Player.removeMediaItem

Link copied to clipboard
open override fun selectChapter(index: Int)

This will seek to the chapter selected by index. If its tried to select a chapter which does not exist an out of bound exception is though.