seekToMediaItem
Selects a media item from the playlist by its index.
Parameters
The index of the media item to play.
Selects a media item from the playlist by its index.
Parameters
The index of the media item to play.
This function takes an integer index
as input, which represents the position of the desired media item within the astroMediaItems
playlist. It performs the following steps:
Safety Check: The function first verifies if the provided
index
is within the valid range of the playlist. If the index is greater than the size of the playlist minus one (indicating an out-of-bounds index), the function exits without making any changes.Update Index: If the index is valid, the
currentMediaItemIndex
property is updated to point to the selected media item. This essentially sets the current position within the playlist.Generate Howl Properties: Similar to the
nextMediaItem
function, a helper function namedcreateHowlProperties
is used. This function takes the source URL of the selected media item (astroMediaItems[index].source
) and creates a newHowlProperties
object. It also copies the current playback settings (volume, html5, loop, etc.) from thenativeMediaPlayer
object to ensure consistent playback behavior.Create New Howl Instance: A new
Howl
instance is created using the generatedHowlProperties
. This effectively replaces the existing player with the selected media item, starting playback from the beginning.
By following these steps, the seekToMediaItem
function allows you to navigate the playlist and play any media item based on its index.