feat: add mute and unmute functionality to player service; update CompactPlayer and Player components to utilize new methods
This commit is contained in:
@@ -27,10 +27,10 @@ export function CompactPlayer({ className }: CompactPlayerProps) {
|
||||
status: 'stopped',
|
||||
mode: 'continuous',
|
||||
volume: 80,
|
||||
previous_volume: 50,
|
||||
position: 0
|
||||
})
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [previousVolume, setPreviousVolume] = useState(50)
|
||||
|
||||
// Load initial state
|
||||
useEffect(() => {
|
||||
@@ -58,12 +58,6 @@ export function CompactPlayer({ className }: CompactPlayerProps) {
|
||||
}
|
||||
}, [])
|
||||
|
||||
// Initialize previous volume when state loads
|
||||
useEffect(() => {
|
||||
if (state.volume > 0 && previousVolume <= 0) {
|
||||
setPreviousVolume(state.volume)
|
||||
}
|
||||
}, [state.volume, previousVolume])
|
||||
|
||||
const executeAction = useCallback(async (action: () => Promise<void | MessageResponse>, actionName: string) => {
|
||||
setIsLoading(true)
|
||||
@@ -96,13 +90,12 @@ export function CompactPlayer({ className }: CompactPlayerProps) {
|
||||
const handleVolumeToggle = useCallback(() => {
|
||||
if (state.volume === 0) {
|
||||
// Unmute
|
||||
executeAction(() => playerService.setVolume(previousVolume), 'unmute')
|
||||
executeAction(playerService.unmute, 'unmute')
|
||||
} else {
|
||||
// Mute
|
||||
setPreviousVolume(state.volume)
|
||||
executeAction(() => playerService.setVolume(0), 'mute')
|
||||
executeAction(playerService.mute, 'mute')
|
||||
}
|
||||
}, [previousVolume, state.volume, executeAction])
|
||||
}, [state.volume, executeAction])
|
||||
|
||||
// Don't show if no current sound
|
||||
if (!state.current_sound) {
|
||||
|
||||
Reference in New Issue
Block a user