Skip to content

Redux Controls Slice API Reference ​

This API reference documents the Redux controls slice used for managing music player state including playlists, playback, history, favorites, and audio controls.

Playlist Management ​

addRecommendationInThePlaylist(songs: SongReduxPlaylistSchema[]) ​

Appends new songs to the end of the existing playlist without changing the active song.

addSongsInThePlaylist(songs: SongReduxPlaylistSchema[]) ​

Replaces the entire playlist with a new set of songs and sets the active song index to 0.

  • Clears existing playlist
  • Sets activeSongIndex to 0
  • Sets isPlaying to false
  • Sets isReady to false

History Management ​

addActiveSongInTheHistory() ​

Adds the currently active song to the history.

  • If the song already exists in history, it's removed from its current position
  • The song is then added to the beginning of the history array

Favorites Management ​

addSongInTheFavourites({ songId: string }) ​

Adds a song to the favorites collection.

  • Adds the songId to the beginning of the favorites array

removeSongFromTheFavourites({ songId: string }) ​

Removes a song from the favorites collection.

  • Filters out the specified songId from the favorites array

Playback Control ​

changeActiveSongTrackByStep(step: number) ​

Changes the active song by a relative step (forward or backward).

  • Validates that the new index is within bounds
  • Resets progress indicators
  • Sets isPlaying to false
  • Sets isReady to false

changeActiveSongTrack({ songId: string }) ​

Changes the active song to a specific song by its ID.

  • Finds the song index in the playlist
  • Resets progress indicators
  • Sets isPlaying to false
  • Sets isReady to false

setActiveSongIndex(index: number) ​

Directly sets the active song index without changing other playback states.

setIsReady(isReady: boolean) ​

Sets whether the current song is ready for playback.

setIsPlaying(isPlaying: boolean) ​

Sets the playing state of the current song.

setRepeatOfActiveSong(loop: boolean) ​

Sets whether the active song should loop when it ends.

Playback Progress ​

setBufferedProgress(buffered: number) ​

Sets the buffered duration of the active song.

setTotalSongDuration(duration: number) ​

Sets the total duration of the active song.

setSeekProgress(progress: number) ​

Sets the current playback position of the active song.

setIsSeeking(isSeeking: boolean) ​

Sets whether the user is currently seeking within the track.

setActiveSongPlayback({ seekPercentage?: number; seekTime?: number }) ​

Sets the playback position of the active song either by percentage or absolute time.

  • Accepts either seekPercentage (0-100) or seekTime (seconds)
  • Throws an error if both are provided
  • Sets isSeeking to true

Volume Control ​

setVolume(volume: number) ​

Sets the playback volume (0 to 1).

  • Throws an error if the volume is outside the 0-1 range

Selectors ​

Playlist Selectors ​

selectPlaylistSongs(state) ​

Returns the full array of songs in the current playlist.

selectActiveSongIndex(state) ​

Returns the current active song index.

selectActiveSong(state) ​

Returns the currently active song object.

Playback State Selectors ​

selectActiveSongStates(state) ​

Returns the complete active song state object.

selectIsActiveSongCurrentlyPlaying(state) ​

Returns whether the active song is currently playing.

selectIsMusicToBeRepeated(state) ​

Returns whether the current song is set to loop.

Progress Selectors ​

selectTotalSongDurationOfActiveSong(state) ​

Returns the total duration of the active song in seconds.

selectActiveSongSeekProgress(state) ​

Returns the current playback position in seconds.

User Collections Selectors ​

selectHistorySongIds(state) ​

Returns the array of song IDs in the listening history.

selectFavouriteSongIds(state) ​

Returns the array of song IDs in the favorites collection.

Volume Selector ​

selectVolumeBarProgress(state) ​

Returns the current volume level (0-1).

just a timepass anyways