|
| 1 | +"use client" |
| 2 | +import { Button } from "@/components/ui/button" |
| 3 | +import { Slider } from "@/components/ui/slider" |
| 4 | +import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuItem } from "@/components/ui/dropdown-menu" |
| 5 | +import { usePlayer } from "@/lib/hooks" |
| 6 | +import { useEffect } from "react" |
| 7 | +import { FaCirclePause, FaPlay, FaForward, FaBackward, FaVolumeHigh, FaShare, FaChevronDown, FaX } from "react-icons/fa6"; |
| 8 | + |
| 9 | +export default function PlayerFloating() { |
| 10 | + const { audioRef, podcast, setPodcast } = usePlayer(); |
| 11 | + |
| 12 | + useEffect(() => { |
| 13 | + if (!podcast?.src) { |
| 14 | + setPodcast((pod) => { |
| 15 | + return { |
| 16 | + ...pod, |
| 17 | + src: 'https://traffic.megaphone.fm/APO7656568543.mp3' |
| 18 | + } |
| 19 | + }) |
| 20 | + } |
| 21 | + }, []); |
| 22 | + |
| 23 | + return ( |
| 24 | + <div className="fixed inset-x-0 bottom-0 z-50 bg-background shadow-lg md:rounded-t-xl"> |
| 25 | + <div className="flex items-center justify-between px-4 py-3 md:px-6 md:py-4"> |
| 26 | + <div className="flex items-center gap-4"> |
| 27 | + <Button variant="ghost" size="icon" onClick={() => audioRef.current!.currentTime -= 30.0}> |
| 28 | + <FaBackward className="h-5 w-5" /> |
| 29 | + </Button> |
| 30 | + {podcast?.isPlaying ? ( |
| 31 | + <Button variant="ghost" size="icon" onClick={() => audioRef.current?.pause()}> |
| 32 | + <FaCirclePause className="h-5 w-5" /> |
| 33 | + </Button> |
| 34 | + ) : |
| 35 | + ( |
| 36 | + <Button variant="ghost" size="icon" onClick={() => audioRef.current?.play()}> |
| 37 | + <FaPlay className="h-5 w-5" /> |
| 38 | + </Button> |
| 39 | + )} |
| 40 | + <Button variant="ghost" size="icon" onClick={() => audioRef.current!.currentTime += 30.0}> |
| 41 | + <FaForward className="h-5 w-5" /> |
| 42 | + </Button> |
| 43 | + </div> |
| 44 | + <div className="flex-1"> |
| 45 | + <Slider |
| 46 | + className="[&>span:first-child]:h-1 [&>span:first-child]:bg-primary [&_[role=slider]]:bg-primary [&_[role=slider]]:w-3 [&_[role=slider]]:h-3 [&_[role=slider]]:border-0 [&>span:first-child_span]:bg-primary [&_[role=slider]:focus-visible]:ring-0 [&_[role=slider]:focus-visible]:ring-offset-0 [&_[role=slider]:focus-visible]:scale-105 [&_[role=slider]:focus-visible]:transition-transform" |
| 47 | + min={0} |
| 48 | + max={podcast.duration} |
| 49 | + value={[podcast.curTime]} |
| 50 | + onChange={(val) => { |
| 51 | + audioRef.current!.currentTime = +val; |
| 52 | + }} |
| 53 | + /> |
| 54 | + </div> |
| 55 | + <div className="flex items-center gap-4"> |
| 56 | + <DropdownMenu> |
| 57 | + <DropdownMenuTrigger asChild> |
| 58 | + <Button variant="ghost" size="icon"> |
| 59 | + 1x |
| 60 | + </Button> |
| 61 | + </DropdownMenuTrigger> |
| 62 | + <DropdownMenuContent align="end"> |
| 63 | + <DropdownMenuLabel>Playback Speed</DropdownMenuLabel> |
| 64 | + <DropdownMenuSeparator /> |
| 65 | + <DropdownMenuItem>0.5x</DropdownMenuItem> |
| 66 | + <DropdownMenuItem>1x</DropdownMenuItem> |
| 67 | + <DropdownMenuItem>1.5x</DropdownMenuItem> |
| 68 | + <DropdownMenuItem>2x</DropdownMenuItem> |
| 69 | + </DropdownMenuContent> |
| 70 | + </DropdownMenu> |
| 71 | + <Slider |
| 72 | + className="w-20 [&>span:first-child]:h-1 [&>span:first-child]:bg-primary [&_[role=slider]]:bg-primary [&_[role=slider]]:w-3 [&_[role=slider]]:h-3 [&_[role=slider]]:border-0 [&>span:first-child_span]:bg-primary [&_[role=slider]:focus-visible]:ring-0 [&_[role=slider]:focus-visible]:ring-offset-0 [&_[role=slider]:focus-visible]:scale-105 [&_[role=slider]:focus-visible]:transition-transform" |
| 73 | + defaultValue={[80]} |
| 74 | + /> |
| 75 | + <Button variant="ghost" size="icon"> |
| 76 | + <FaVolumeHigh className="h-5 w-5" /> |
| 77 | + </Button> |
| 78 | + </div> |
| 79 | + <div className="ml-auto flex items-center gap-4"> |
| 80 | + <Button variant="ghost" size="icon"> |
| 81 | + <FaShare className="h-5 w-5" /> |
| 82 | + </Button> |
| 83 | + <Button variant="ghost" size="icon"> |
| 84 | + <FaChevronDown className="h-5 w-5" /> |
| 85 | + </Button> |
| 86 | + <Button variant="ghost" size="icon"> |
| 87 | + <FaX className="h-5 w-5" /> |
| 88 | + </Button> |
| 89 | + </div> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + ) |
| 93 | +} |
0 commit comments