Skip to content

Commit

Permalink
Fix pause and mute audio start position (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluesmile82 authored Mar 25, 2022
1 parent 817af45 commit ca2c1c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const AudioPlayer = ({
script,
textMark,
setTextMark,
setPlayedSeconds,
}) => (
<ReactPlayer
url={[`${file}#t=${startTime},${endTime}`]}
Expand Down Expand Up @@ -45,6 +46,8 @@ const AudioPlayer = ({
setTextMark(textMark + 1);
}
}

setPlayedSeconds(playedSeconds);
}}
progressInterval={50}
config={{
Expand Down
13 changes: 12 additions & 1 deletion src/containers/onboarding/sound-btn/sound-btn-component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const ButtonIcon = ({
stepsNumber,
onBoardingStep,
pauseIcon,
setPausedTime,
playedSeconds,
}) => {
const renderAudioBars = () => (
<div className={styles.audioBars} onMouseEnter={() => setPauseIcon(true)}>
Expand Down Expand Up @@ -87,6 +89,7 @@ const ButtonIcon = ({
onMouseLeave={() => setPauseIcon(false)}
onClick={() => {
setPlaying(false);
setPausedTime(playedSeconds);
}}
>
<PauseIcon className={styles.pauseIcon} />
Expand All @@ -108,6 +111,8 @@ const SoundButtonComponent = ({
waitingInteraction,
}) => {
const [playing, setPlaying] = useState(true);
const [playedSeconds, setPlayedSeconds] = useState(0);
const [pausedTime, setPausedTime] = useState(0);
const [muted, setMuted] = useState(false);

// There is no autoplay on chrome and firefos. We always need a previous user click on the page.
Expand All @@ -124,6 +129,7 @@ const SoundButtonComponent = ({

const toggleMuted = () => {
setMuted(!muted);
setPausedTime(playedSeconds);
};

const handlePlay = () => {
Expand Down Expand Up @@ -221,7 +227,6 @@ const SoundButtonComponent = ({
<AudioPlayer
{...{
file,
startTime,
endTime,
muted,
freeToPlay,
Expand All @@ -233,7 +238,11 @@ const SoundButtonComponent = ({
script,
textMark,
setTextMark,
setPlayedSeconds,
setPausedTime,
pausedTime,
}}
startTime={pausedTime || startTime}
/>
<ButtonIcon
{...{
Expand All @@ -246,6 +255,8 @@ const SoundButtonComponent = ({
stepsNumber,
onBoardingStep,
pauseIcon,
setPausedTime,
playedSeconds,
}}
/>
</div>
Expand Down

0 comments on commit ca2c1c6

Please sign in to comment.