NewPlayer

interface NewPlayer

The default implementation of the NewPlayer interface is NewPlayerImpl.

An instance of NewPlayer will contain the business logic of the whole NewPlayer. NewPlayerImpl will therefore also contain the instance of Player.

Keep ind mind that a NewPlayer instance must live in an Application instance. Otherwise, the NewPlayer instance can not outlive an Activity or Service. NewPlayer must be able to do this though in order to

  1. Run in background

  2. If it's executed on a TV: Stop when the main activity is closed. (The reason the NewPlayer instance should not be hosted inside a MediaService, since on TV there should not be a playback service.)

Inheritors

Properties

Link copied to clipboard
abstract val bufferedPercentage: Int

Same as ExoPlayer's bufferedPercentage. See Player.getBufferedPercentage

Link copied to clipboard
abstract 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
abstract 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
abstract 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
abstract val currentlyPlayingTracks: StateFlow<List<StreamTrack>>

The tracks that are currently reproduced by ExoPlayer

Link copied to clipboard
abstract 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
abstract val duration: Long

Same as ExoPlayer's duration. See Player.getDuration

Link copied to clipboard
abstract 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
abstract val exoPlayer: StateFlow<Player?>

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
abstract var fastSeekAmountSec: Int

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

Link copied to clipboard

The Icon that should be shown in the media notification.

Link copied to clipboard
abstract val onExoPlayerEvent: SharedFlow<Pair<Player, Player.Events>>
Link copied to clipboard
abstract val playBackMode: MutableStateFlow<PlayMode>
Link copied to clipboard

The class of the activity that holds the NewPlayerUI.

Link copied to clipboard
abstract 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
abstract var playWhenReady: Boolean

Same as ExoPlayer's playWhenReady. See Player.setPlayWhenReady

Link copied to clipboard

Sets the default languages the user prefers. This can be overridden per stream via currentStreamLanguageConstraint.

Link copied to clipboard
abstract 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

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

Link copied to clipboard
abstract 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
abstract var shuffle: Boolean

Same as ExoPlayer's shuffle. See Player.getShuffleModeEnabled

Functions

Link copied to clipboard
abstract fun addToPlaylist(item: String)

Adds a new item to the playlist.

Link copied to clipboard
abstract 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
abstract fun movePlaylistItem(fromIndex: Int, toIndex: Int)

Same as ExoPlayer's movePlaylistItem. See Player.moveMediaItem

Link copied to clipboard
abstract fun pause()

Same as ExoPlayer's Player.pause

Link copied to clipboard
abstract fun play()

Same as ExoPlayer's Player.play.

Link copied to clipboard
abstract 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
abstract fun prepare()

Same as ExoPlayer's Player.prepare.

Link copied to clipboard
abstract 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
abstract fun removePlaylistItem(uniqueId: Long)

Same as ExoPlayer's removePlaylistItem. See Player.removeMediaItem

Link copied to clipboard
abstract 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.