diff --git a/src/features/audio/index.tsx b/src/features/audio/index.tsx index 366a6a076..61a43d89b 100644 --- a/src/features/audio/index.tsx +++ b/src/features/audio/index.tsx @@ -4,7 +4,7 @@ import throttle from 'lodash/throttle'; import React, { useEffect, useLayoutEffect, useRef, useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; -import Icon from 'soapbox/components/icon'; +import SvgIcon from 'soapbox/components/ui/icon/svg-icon'; import { formatTime, getPointerPosition } from 'soapbox/features/video'; import Visualizer from './visualizer'; @@ -64,10 +64,11 @@ const Audio: React.FC = (props) => { const [duration, setDuration] = useState(undefined); const [paused, setPaused] = useState(true); const [muted, setMuted] = useState(false); + const [preVolume, setPreVolume] = useState(0); const [volume, setVolume] = useState(0.5); const [dragging, setDragging] = useState(false); const [hovered, setHovered] = useState(false); - + const [seekHovered, setSeekHovered] = useState(false); const visualizer = useRef(new Visualizer(TICK_SIZE)); const audioContext = useRef(null); @@ -150,12 +151,20 @@ const Audio: React.FC = (props) => { }; const toggleMute = () => { - const nextMuted = !muted; - - setMuted(nextMuted); - if (audio.current) { - audio.current.muted = nextMuted; + const muted = !audio.current.muted; + setMuted(muted); + audio.current.muted = muted; + + if (muted) { + setPreVolume(audio.current.volume); + audio.current.volume = 0; + setVolume(0); + } else { + audio.current.volume = preVolume; + setVolume(preVolume); + } + } }; @@ -259,6 +268,14 @@ const Audio: React.FC = (props) => { setHovered(false); }; + const handleSeekEnter = () => { + setSeekHovered(true); + }; + + const handleSeekLeave = () => { + setSeekHovered(false); + }; + const handleLoadedData = () => { if (audio.current) { setDuration(audio.current.duration); @@ -438,7 +455,8 @@ const Audio: React.FC = (props) => { return (
= (props) => { width: '100%', height: fullscreen ? '100%' : (height || props.height), }} - onMouseEnter={handleMouseEnter} - onMouseLeave={handleMouseLeave} tabIndex={0} onKeyDown={handleKeyDown} onClick={e => e.stopPropagation()} @@ -466,7 +482,7 @@ const Audio: React.FC = (props) => { = (props) => { /> )} -
+
-
+
-
-
-
+
+
+
- +
- - {formatTime(Math.floor(currentTime))} + + {formatTime(Math.floor(currentTime))} {getDuration() && (<> - / {/* eslint-disable-line formatjs/no-literal-string-in-jsx */} - {formatTime(Math.floor(getDuration()))} + /{/* eslint-disable-line formatjs/no-literal-string-in-jsx */} + {formatTime(Math.floor(getDuration()))} )}
- diff --git a/src/features/video/index.tsx b/src/features/video/index.tsx index 028c1188a..438e84378 100644 --- a/src/features/video/index.tsx +++ b/src/features/video/index.tsx @@ -400,7 +400,7 @@ const Video: React.FC = ({ const toggleMute = () => { if (video.current) { const muted = !video.current.muted; - setMuted(!muted); + setMuted(muted); video.current.muted = muted; if (muted) {