AstroPlayer

expect open class AstroPlayer(nativeMediaPlayer: NativeMediaPLayer)

The main class for controlling media playback.

AstroPlayer provides a set of methods for playing, pausing, seeking, and managing media items in a playlist.

Parameters

nativeMediaPlayer

An implementation of the underlying native media player that AstroPlayer delegates playback functionality to. The specific type of NativeMediaPLayer will vary depending on the platform and the AstroPlayer implementation.

actual open class AstroPlayer
actual open class AstroPlayer

The main class for controlling media playback.

AstroPlayer provides a set of methods for playing, pausing, seeking, and managing media items in a playlist.

Parameters

nativeMediaPlayer

An implementation of the underlying native media player that AstroPlayer delegates playback functionality to. The specific type of NativeMediaPLayer will vary depending on the platform and the AstroPlayer implementation.

Constructors

Link copied to clipboard
expect constructor(nativeMediaPlayer: NativeMediaPLayer)

Creates a new AstroPlayer instance.

Types

Link copied to clipboard
expect object Companion
actual object Companion
actual object Companion

Properties

Link copied to clipboard
expect open val contentDuration: Long

Gets the duration of the current media item in milliseconds.

actual open val contentDuration: Long
actual open val contentDuration: Long

Gets the duration of the current media item in milliseconds.

Link copied to clipboard

Gets the current equalizer values, or null if the equalizer is not enabled or not supported.

Gets the current equalizer values, or null if the equalizer is not enabled or not supported.

Link copied to clipboard

Gets the currently playing media item, or null if no media item is playing.

Gets the currently playing media item, or null if no media item is playing.

Link copied to clipboard
expect open val currentMediaItemIndex: Int

Gets the index of the currently playing media item in the playlist, or -1 if no media item is playing.

actual open val currentMediaItemIndex: Int
actual open val currentMediaItemIndex: Int

Gets the index of the currently playing media item in the playlist, or -1 if no media item is playing.

Link copied to clipboard

The metadata associated with the currently playing media item, or null if no item is playing or the item has no metadata.

Link copied to clipboard
expect open val currentPosition: Long

Gets the current playback position in milliseconds.

actual open val currentPosition: Long
actual open val currentPosition: Long

Gets the current playback position in milliseconds.

Link copied to clipboard

Indicates whether there's a next media item available in the playlist after the current one.

Link copied to clipboard

Indicates whether there's a previous media item available in the playlist before the current one.

Link copied to clipboard

Gets or sets whether the equalizer is enabled.

Gets or sets whether the equalizer is enabled.

Link copied to clipboard
expect open val isMuted: Boolean

Indicates whether the player is muted.

actual open val isMuted: Boolean
actual open val isMuted: Boolean

Indicates whether the player is muted.

Link copied to clipboard
expect open val isPaused: Boolean

Indicates whether the player is currently paused.

actual open val isPaused: Boolean
actual open val isPaused: Boolean

Indicates whether the player is currently paused.

Link copied to clipboard
expect open val isPlaying: Boolean

Indicates whether the player is currently playing media.

actual open val isPlaying: Boolean
actual open val isPlaying: Boolean

Indicates whether the player is currently playing media.

Link copied to clipboard

Gets or sets whether smart equalizer is enabled. When enabled, the player will attempt to apply an equalizer configuration based on the current media item's equalizer ID and the following logic:

Gets or sets whether smart equalizer is enabled. When enabled, the player will attempt to apply an equalizer configuration based on the current media item's equalizer ID and the following logic:

Link copied to clipboard
expect open val mediaItemCount: Int

Gets the total number of media items in the playlist.

actual open val mediaItemCount: Int
actual open val mediaItemCount: Int

Gets the total number of media items in the playlist.

Link copied to clipboard
expect open var playBackSpeed: Float

Gets or sets the playback speed. Values greater than 1.0 indicate faster playback, while values less than 1.0 indicate slower playback.

actual open var playBackSpeed: Float
actual open var playBackSpeed: Float

Gets or sets the playback speed. Values greater than 1.0 indicate faster playback, while values less than 1.0 indicate slower playback.

Link copied to clipboard
expect open var repeatMode: RepeatMode

The current repeat mode of the player.

actual open var repeatMode: RepeatMode
actual open var repeatMode: RepeatMode

The current repeat mode of the player.

Link copied to clipboard
expect open val seekBackIncrement: Long

The default seek backward increment in milliseconds.

actual open val seekBackIncrement: Long = 5000
actual open val seekBackIncrement: Long = 5000

The default seek backward increment in milliseconds.

Link copied to clipboard
expect open val seekForwardIncrement: Long

The default seek forward increment in milliseconds.

actual open val seekForwardIncrement: Long = 5000
actual open val seekForwardIncrement: Long = 5000

The default seek forward increment in milliseconds.

Link copied to clipboard
expect open var shuffleModeEnabled: Boolean

Indicates whether shuffle mode is enabled.

actual open var shuffleModeEnabled: Boolean
actual open var shuffleModeEnabled: Boolean

Indicates whether shuffle mode is enabled.

Link copied to clipboard

An optional callback function that allows you to provide custom equalizer values for specific equalizer preset IDs. This property is used for smart equalizers, where the player can dynamically adjust the sound based on the selected preset.

An optional callback function that allows you to provide custom equalizer values for specific equalizer preset IDs. This property is used for smart equalizers, where the player can dynamically adjust the sound based on the selected preset.

Link copied to clipboard
expect open val volume: Float

Gets the current volume level of the player. The value ranges from 0.0 (silent) to 1.0 (maximum volume).

actual open val volume: Float
actual open val volume: Float

Gets the current volume level of the player. The value ranges from 0.0 (silent) to 1.0 (maximum volume).

Functions

Link copied to clipboard

Registers a listener to receive notifications about playback and media state changes in AstroPlayer.

Link copied to clipboard
expect open fun addMediaItem(item: AstroMediaItem)

Adds a media item to the playlist.

expect open fun addMediaItem(index: Int, item: AstroMediaItem)

Inserts a media item at a specific index in the playlist.

actual open fun addMediaItem(item: AstroMediaItem)
actual open fun addMediaItem(index: Int, item: AstroMediaItem)
actual open fun addMediaItem(item: AstroMediaItem)

Adds a media item to the playlist.

actual open fun addMediaItem(index: Int, item: AstroMediaItem)

Inserts a media item at a specific index in the playlist.

Link copied to clipboard
expect open fun addMediaItems(items: List<AstroMediaItem>)

Adds a list of media items to the end of the playlist.

expect open fun addMediaItems(index: Int, items: List<AstroMediaItem>)

Inserts a list of media items at a specific index in the playlist.

actual open fun addMediaItems(items: List<AstroMediaItem>)
actual open fun addMediaItems(index: Int, items: List<AstroMediaItem>)
actual open fun addMediaItems(items: List<AstroMediaItem>)

Adds a list of media items to the end of the playlist.

actual open fun addMediaItems(index: Int, items: List<AstroMediaItem>)

Inserts a list of media items at a specific index in the playlist.

Link copied to clipboard
expect open fun allMediaItems(): List<AstroMediaItem>

Returns a list containing all media items in the playlist.

actual open fun allMediaItems(): List<AstroMediaItem>
actual open fun allMediaItems(): List<AstroMediaItem>

Returns a list containing all media items in the playlist.

Link copied to clipboard
expect open fun clearMediaItems()

Removes all media items from the playlist.

actual open fun clearMediaItems()
actual open fun clearMediaItems()

Removes all media items from the playlist.

Link copied to clipboard

Clears the current playlist and then adds a single media item.

Clears the current playlist and then adds a single media item at a specific index.

Link copied to clipboard

Clears the current playlist and then adds a collection of media items.

Clears the current playlist and then adds a collection of media items at a specific index.

Link copied to clipboard
expect open fun decreaseVolume()

Decreases the player volume.

actual open fun decreaseVolume()
actual open fun decreaseVolume()

Decreases the player volume.

Link copied to clipboard
expect open fun decreaseVolumeBy(offset: Float)

Decreases the player volume by a specified offset.

actual open fun decreaseVolumeBy(offset: Float)
actual open fun decreaseVolumeBy(offset: Float)

Decreases the player volume by a specified offset.

Link copied to clipboard
Link copied to clipboard
expect open fun increaseVolume()

Increases the player volume.

actual open fun increaseVolume()
actual open fun increaseVolume()

Increases the player volume.

Link copied to clipboard
expect open fun increaseVolumeBy(offset: Float)

Increases the player volume by a specified offset.

actual open fun increaseVolumeBy(offset: Float)
actual open fun increaseVolumeBy(offset: Float)

Increases the player volume by a specified offset.

Link copied to clipboard
expect open fun <T> mapMediaItems(transform: (AstroMediaItem) -> T): List<T>

Applies a transformation function to each media item in the playlist and returns a list of the transformed results.

actual open fun <T> mapMediaItems(transform: (AstroMediaItem) -> T): List<T>
actual open fun <T> mapMediaItems(transform: (AstroMediaItem) -> T): List<T>

Applies a transformation function to each media item in the playlist and returns a list of the transformed results.

Link copied to clipboard
expect open fun moveMediaItem(currentIndex: Int, newIndex: Int)

Moves a media item from one index to another in the playlist.

actual open fun moveMediaItem(currentIndex: Int, newIndex: Int)
actual open fun moveMediaItem(currentIndex: Int, newIndex: Int)

Moves a media item from one index to another in the playlist.

Link copied to clipboard
expect open fun moveMediaItems(fromIndex: Int, toIndex: Int, newIndex: Int)

Moves a range of media items from one index to another in the playlist.

actual open fun moveMediaItems(fromIndex: Int, toIndex: Int, newIndex: Int)
actual open fun moveMediaItems(fromIndex: Int, toIndex: Int, newIndex: Int)

Moves a range of media items from one index to another in the playlist.

Link copied to clipboard
expect open fun mute()

Mutes the player.

actual open fun mute()
actual open fun mute()

Mutes the player.

Link copied to clipboard
expect open fun pause()

Pauses playback of the current media item.

actual open fun pause()
actual open fun pause()

Pauses playback of the current media item.

Link copied to clipboard
expect open fun play()

Starts playback of the current media item.

actual open fun play()
actual open fun play()

Starts playback of the current media item.

Link copied to clipboard
expect open fun prepare()

Prepares the player for playback. This might involve buffering the media stream.

actual open fun prepare()
actual open fun prepare()

Prepares the player for playback. This might involve buffering the media stream.

Link copied to clipboard
expect open fun release()

Releases the player resources. This should be called when the player is no longer needed.

actual open fun release()
actual open fun release()

Releases the player resources. This should be called when the player is no longer needed.

Link copied to clipboard

Unregisters a previously registered listener from receiving notifications from AstroPlayer.

Link copied to clipboard
expect open fun removeMediaItem(index: Int)

Removes a media item from the playlist by its index.

actual open fun removeMediaItem(index: Int)
actual open fun removeMediaItem(index: Int)

Removes a media item from the playlist by its index.

Link copied to clipboard
expect open fun removeMediaItems(fromIndex: Int, toIndex: Int)

Removes a range of media items from the playlist.

actual open fun removeMediaItems(fromIndex: Int, toIndex: Int)
actual open fun removeMediaItems(fromIndex: Int, toIndex: Int)

Removes a range of media items from the playlist.

Link copied to clipboard
expect open fun replaceMediaItem(index: Int, mediaItem: AstroMediaItem)

Replaces a media item at a specific index in the playlist.

actual open fun replaceMediaItem(index: Int, mediaItem: AstroMediaItem)
actual open fun replaceMediaItem(index: Int, mediaItem: AstroMediaItem)

Replaces a media item at a specific index in the playlist.

Link copied to clipboard
expect open fun replaceMediaItems(fromIndex: Int, toIndex: Int, mediaItems: List<AstroMediaItem>)

Replaces a range of media items in the playlist with a new list of media items.

actual open fun replaceMediaItems(fromIndex: Int, toIndex: Int, mediaItems: List<AstroMediaItem>)
actual open fun replaceMediaItems(fromIndex: Int, toIndex: Int, mediaItems: List<AstroMediaItem>)

Replaces a range of media items in the playlist with a new list of media items.

Link copied to clipboard
fun AstroPlayer.seekBackwardBy(milliseconds: Long)

Seeks the playback position backward by the specified number of milliseconds.

Link copied to clipboard

Seeks the playback position backward by the default seek backward increment.

Link copied to clipboard
fun AstroPlayer.seekForwardBy(milliseconds: Long)

Seeks the playback position forward by the specified number of milliseconds.

Link copied to clipboard

Seeks the playback position forward by the default seek forward increment.

Link copied to clipboard
expect open fun seekTo(milliseconds: Long)

Seeks to a specific position in the current media item in milliseconds.

actual open fun seekTo(milliseconds: Long)
actual open fun seekTo(milliseconds: Long)

Seeks to a specific position in the current media item in milliseconds.

Link copied to clipboard

Seeks the playback position to the end of the current media item.

Link copied to clipboard
expect open fun seekToMediaItem(index: Int)

Selects a media item from the playlist by its index.

actual open fun seekToMediaItem(index: Int)
actual open fun seekToMediaItem(index: Int)

Selects a media item from the playlist by its index.

Link copied to clipboard
fun AstroPlayer.seekToMediaItemThenAt(index: Int, milliseconds: Long)

Seeks to a specific media item and then sets the playback position within that item.

Link copied to clipboard

Seeks to the next media item in the playlist, if available.

Link copied to clipboard

Seeks to the previous media item in the playlist, if available.

Link copied to clipboard

Seeks the playback position to the beginning of the current media item.

Link copied to clipboard
expect open fun unMute()

Unmutes the player.

actual open fun unMute()
actual open fun unMute()

Unmutes the player.