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
indexis 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
currentMediaItemIndexproperty is updated to point to the selected media item. This essentially sets the current position within the playlist.Generate Howl Properties: Similar to the
nextMediaItemfunction, a helper function namedcreateHowlPropertiesis used. This function takes the source URL of the selected media item (astroMediaItems[index].source) and creates a newHowlPropertiesobject. It also copies the current playback settings (volume, html5, loop, etc.) from thenativeMediaPlayerobject to ensure consistent playback behavior.Create New Howl Instance: A new
Howlinstance 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.