diff --git a/src/components/Player.jsx b/src/components/Player.jsx
index afd2ce3..d2f74ff 100644
--- a/src/components/Player.jsx
+++ b/src/components/Player.jsx
@@ -2,6 +2,14 @@ import { usePlayerStore } from "@/store/playerStore"
import { useEffect, useRef, useState } from "react"
import { Slider } from "./Slider"
+
+export const Prev = () => (
+
+)
+export const Next = () => (
+
+)
+
export const Pause = ({ className }) => (
)
@@ -12,11 +20,11 @@ export const Play = ({ className }) => (
export const VolumeSilence = () => (
-)
+)
export const Volume = () => (
- )
+)
const CurrentSong = ({ image, title, artists }) => {
return (
@@ -25,18 +33,18 @@ const CurrentSong = ({ image, title, artists }) => {
flex items-center gap-5 relative
overflow-hidden
`}>
-
-
-
-
-
-
- {title}
-
-
- {artists?.join(', ')}
-
-
+
+
+
+
+
+
+ {title}
+
+
+ {artists?.join(', ')}
+
+
)
@@ -113,7 +121,7 @@ const VolumeControl = () => {
-
+
{
)
}
-export function Player () {
- const { currentMusic, isPlaying, setIsPlaying, volume } = usePlayerStore(state => state)
+export function Player() {
+ const { currentMusic, setCurrentMusic, isPlaying, setIsPlaying, volume } = usePlayerStore(state => state)
const audioRef = useRef()
useEffect(() => {
@@ -158,6 +166,32 @@ export function Player () {
setIsPlaying(!isPlaying)
}
+ const getSongIndex = (id) => {
+ return currentMusic.songs.findIndex(e => e.id === id) ?? -1
+ }
+
+ const onNextSong = () => {
+ const { song, playlist, songs } = currentMusic;
+ const index = getSongIndex(song.id)
+ if (index > -1 && index + 1 < songs.length) {
+ setIsPlaying(false);
+ setCurrentMusic({ songs, playlist, song: songs[index + 1] })
+ setIsPlaying(true);
+ }
+ }
+
+ const onPrevSong = () => {
+
+ const { song, playlist, songs } = currentMusic;
+ const index = getSongIndex(song.id)
+ if (index > -1 && index > 0) {
+ setIsPlaying(false);
+ setCurrentMusic({ songs, playlist, song: songs[index - 1] })
+ setIsPlaying(true);
+ }
+ }
+
+
return (
@@ -166,9 +200,20 @@ export function Player () {
-
+
+
+
+
+