-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55d4e49
commit 7b212ef
Showing
6 changed files
with
212 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
audio::-webkit-media-controls-panel { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
/* background: transparent; */ | ||
} | ||
|
||
audio::-webkit-media-controls-play-button{ | ||
transform: scale(2.5); | ||
/* background-color: black; */ | ||
|
||
} | ||
audio::-webkit-media-controls-timeline-container, | ||
audio::-webkit-media-controls-current-time-display, | ||
audio::-webkit-media-controls-time-remaining-display, | ||
audio::-webkit-media-controls-mute-button, | ||
audio::-webkit-media-controls-volume-slider { | ||
display: none !important; | ||
width: 0 !important; | ||
height: 0 !important; | ||
margin: 0 !important; | ||
padding: 0 !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
"use client"; | ||
import React, { useRef } from "react"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuTrigger, | ||
DropdownMenuContent, | ||
DropdownMenuSeparator, | ||
DropdownMenuItem, | ||
DropdownMenuLabel, | ||
} from "@/components/ui/dropdownmeu"; | ||
import { useStore } from "@/store"; | ||
import { ChevronDown } from "lucide-react"; | ||
import "../assets/audio.css"; | ||
|
||
type Props = {}; | ||
|
||
const AudioPlayer = (props: Props) => { | ||
const { | ||
audioSrc, | ||
currentTrackIndex, | ||
isPlaying, | ||
pause, | ||
play, | ||
playNextTrack, | ||
playTrack, | ||
queueTracks, | ||
reset, | ||
setAudioSrc, | ||
tracks, | ||
} = useStore(); | ||
const audioRef = useRef<HTMLAudioElement>(null); | ||
const currentTrack = | ||
currentTrackIndex !== null ? tracks[currentTrackIndex] : null; | ||
// console.log("currentTrack", currentTrack) | ||
|
||
const handlePlay = () => { | ||
if (currentTrackIndex === null) { | ||
console.log("no current track"); | ||
playTrack(0); | ||
} else { | ||
play(); | ||
if (audioRef.current) { | ||
if (audioRef.current.paused) { | ||
audioRef.current.play(); | ||
} | ||
} | ||
} | ||
}; | ||
const handleReset = () => { | ||
reset(); | ||
if (audioRef.current) { | ||
if (!audioRef.current.paused) { | ||
audioRef.current.pause(); | ||
} | ||
} | ||
}; | ||
|
||
const handlePause = () => { | ||
if (audioRef.current) { | ||
if (!audioRef.current.paused) { | ||
audioRef.current.pause(); | ||
} | ||
} | ||
console.log("pause", isPlaying); | ||
pause(); | ||
console.log("pause", isPlaying); | ||
}; | ||
|
||
const handleEnded = () => { | ||
console.log("ended the track"); | ||
playNextTrack(); | ||
}; | ||
|
||
const handleTrackClick = (index: number) => { | ||
console.log("track clicked", index); | ||
playTrack(index); | ||
}; | ||
|
||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger className="flex items-center gap-2 outline-none"> | ||
{/* {currentTrack ? ( */} | ||
<audio | ||
ref={audioRef} | ||
src={currentTrack ? currentTrack?.src : undefined} | ||
onEnded={handleEnded} | ||
autoPlay={isPlaying} | ||
controls | ||
controlsList="nodownload noplaybackrate" | ||
className="max-h-[60px]" | ||
></audio> | ||
{/* ) : null} */} | ||
Music | ||
<ChevronDown /> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent className=" grid grid-cols-2 bg-background max-w-[700px]"> | ||
<div> | ||
<DropdownMenuLabel>Title</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
{tracks.map((track: any, index) => ( | ||
<DropdownMenuItem | ||
key={track.id} | ||
onClick={() => handleTrackClick(index)} | ||
> | ||
{track.title.split(" ").slice(0, 5).join(" ")} | ||
</DropdownMenuItem> | ||
))} | ||
</div> | ||
<div className="flex flex-col gap-4"> | ||
<button onClick={handlePlay}>Play</button> | ||
<button onClick={handlePause}>Pause</button> | ||
<button onClick={handleReset}>Reset</button> | ||
</div> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
}; | ||
|
||
export default AudioPlayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters