import React, { HTMLAttributes, useState, useRef } from 'react'; import classNames from 'classnames'; import { FaPlay, FaPause, FaStepForward, FaStepBackward, FaVolumeUp, FaDesktop, FaStop } from 'react-icons/fa'; import { Features } from '../api/player'; interface NowPlayingProps extends HTMLAttributes { songName: string; fileName: string; isPlaying: boolean; isIdle: boolean; volume: number; timePosition?: number; duration?: number; seekable?: boolean; onPlayPause: () => void; onStop: () => void; onSkip: () => void; onPrevious: () => void; onSeek: (time: number) => void; onScreenShare: () => void; isScreenSharingSupported: boolean; isScreenSharing: boolean; // Sent when the volume setting actually changes value onVolumeSettingChange: (volume: number) => void; // Sent when the volume is about to start changing onVolumeWillChange: (volume: number) => void; // Sent when the volume has changed onVolumeDidChange: (volume: number) => void; features: Features | null; audioEnabled: boolean; onAudioEnabledChange: (enabled: boolean) => void; } const NowPlaying: React.FC = (props) => { const [isSeeking, setIsSeeking] = useState(false); const progressBarRef = useRef(null); const formatTime = (time: number) => { const minutes = Math.floor(time / 60); const seconds = Math.floor(time % 60); return `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`; }; const handleSeek = (e: React.MouseEvent) => { if (progressBarRef.current) { const rect = progressBarRef.current.getBoundingClientRect(); const newSeekPosition = (e.clientX - rect.left) / rect.width; if (props.duration) { props.onSeek(newSeekPosition * props.duration); } } }; const titleArea = props.isScreenSharing ? (
Screen Sharing
) : (
{props.songName}
{props.fileName}
{props.timePosition && props.duration ? (props.seekable ? `${formatTime(props.timePosition)} / ${formatTime(props.duration)}` : `${formatTime(props.timePosition)}` ) : ''}
); return (
{titleArea}
props.onVolumeWillChange(props.volume)} onMouseUp={() => props.onVolumeDidChange(props.volume)} onChange={(e) => props.onVolumeSettingChange(Number(e.target.value))} className="fancy-slider h-2 w-full" />
{(props.isScreenSharingSupported && props.features?.screenshare) && ( )}
{props.seekable !== false && (
{ setIsSeeking(true); handleSeek(e); }} onMouseMove={(e) => { if (isSeeking) { handleSeek(e); } }} onMouseUp={() => setIsSeeking(false)} onMouseLeave={() => setIsSeeking(false)} >
)} {props.features?.browserPlayback && (
)}
); }; export default NowPlaying;