Add voice broadcast seek 30s forward/backward buttons (#9592)
This commit is contained in:
parent
caac059479
commit
d699f5607b
13 changed files with 316 additions and 11 deletions
|
@ -26,6 +26,7 @@ type AccessibleButtonKind = | 'primary'
|
|||
| 'primary_outline'
|
||||
| 'primary_sm'
|
||||
| 'secondary'
|
||||
| 'secondary_content'
|
||||
| 'content_inline'
|
||||
| 'danger'
|
||||
| 'danger_outline'
|
||||
|
|
|
@ -651,6 +651,8 @@
|
|||
"play voice broadcast": "play voice broadcast",
|
||||
"resume voice broadcast": "resume voice broadcast",
|
||||
"pause voice broadcast": "pause voice broadcast",
|
||||
"30s backward": "30s backward",
|
||||
"30s forward": "30s forward",
|
||||
"Go live": "Go live",
|
||||
"Live": "Live",
|
||||
"Voice broadcast": "Voice broadcast",
|
||||
|
|
39
src/voice-broadcast/components/atoms/SeekButton.tsx
Normal file
39
src/voice-broadcast/components/atoms/SeekButton.tsx
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
|
||||
import AccessibleButton from "../../../components/views/elements/AccessibleButton";
|
||||
|
||||
interface Props {
|
||||
icon: React.FC<React.SVGProps<SVGSVGElement>>;
|
||||
label: string;
|
||||
onClick: () => void;
|
||||
}
|
||||
|
||||
export const SeekButton: React.FC<Props> = ({
|
||||
onClick,
|
||||
icon: Icon,
|
||||
label,
|
||||
}) => {
|
||||
return <AccessibleButton
|
||||
kind="secondary_content"
|
||||
onClick={onClick}
|
||||
aria-label={label}
|
||||
>
|
||||
<Icon className="mx_Icon mx_Icon_24" />
|
||||
</AccessibleButton>;
|
||||
};
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import React, { ReactElement } from "react";
|
||||
|
||||
import {
|
||||
VoiceBroadcastControl,
|
||||
|
@ -26,9 +26,14 @@ import Spinner from "../../../components/views/elements/Spinner";
|
|||
import { useVoiceBroadcastPlayback } from "../../hooks/useVoiceBroadcastPlayback";
|
||||
import { Icon as PlayIcon } from "../../../../res/img/element-icons/play.svg";
|
||||
import { Icon as PauseIcon } from "../../../../res/img/element-icons/pause.svg";
|
||||
import { Icon as Back30sIcon } from "../../../../res/img/element-icons/Back30s.svg";
|
||||
import { Icon as Forward30sIcon } from "../../../../res/img/element-icons/Forward30s.svg";
|
||||
import { _t } from "../../../languageHandler";
|
||||
import Clock from "../../../components/views/audio_messages/Clock";
|
||||
import SeekBar from "../../../components/views/audio_messages/SeekBar";
|
||||
import { SeekButton } from "../atoms/SeekButton";
|
||||
|
||||
const SEEK_TIME = 30;
|
||||
|
||||
interface VoiceBroadcastPlaybackBodyProps {
|
||||
playback: VoiceBroadcastPlayback;
|
||||
|
@ -40,10 +45,11 @@ export const VoiceBroadcastPlaybackBody: React.FC<VoiceBroadcastPlaybackBodyProp
|
|||
const {
|
||||
duration,
|
||||
liveness,
|
||||
playbackState,
|
||||
position,
|
||||
room,
|
||||
sender,
|
||||
toggle,
|
||||
playbackState,
|
||||
} = useVoiceBroadcastPlayback(playback);
|
||||
|
||||
let control: React.ReactNode;
|
||||
|
@ -76,6 +82,31 @@ export const VoiceBroadcastPlaybackBody: React.FC<VoiceBroadcastPlaybackBodyProp
|
|||
/>;
|
||||
}
|
||||
|
||||
let seekBackwardButton: ReactElement | null = null;
|
||||
let seekForwardButton: ReactElement | null = null;
|
||||
|
||||
if (playbackState !== VoiceBroadcastPlaybackState.Stopped) {
|
||||
const onSeekBackwardButtonClick = () => {
|
||||
playback.skipTo(Math.max(0, position - SEEK_TIME));
|
||||
};
|
||||
|
||||
seekBackwardButton = <SeekButton
|
||||
icon={Back30sIcon}
|
||||
label={_t("30s backward")}
|
||||
onClick={onSeekBackwardButtonClick}
|
||||
/>;
|
||||
|
||||
const onSeekForwardButtonClick = () => {
|
||||
playback.skipTo(Math.min(duration, position + SEEK_TIME));
|
||||
};
|
||||
|
||||
seekForwardButton = <SeekButton
|
||||
icon={Forward30sIcon}
|
||||
label={_t("30s forward")}
|
||||
onClick={onSeekForwardButtonClick}
|
||||
/>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mx_VoiceBroadcastBody">
|
||||
<VoiceBroadcastHeader
|
||||
|
@ -85,7 +116,9 @@ export const VoiceBroadcastPlaybackBody: React.FC<VoiceBroadcastPlaybackBodyProp
|
|||
showBroadcast={true}
|
||||
/>
|
||||
<div className="mx_VoiceBroadcastBody_controls">
|
||||
{ seekBackwardButton }
|
||||
{ control }
|
||||
{ seekForwardButton }
|
||||
</div>
|
||||
<div className="mx_VoiceBroadcastBody_timerow">
|
||||
<SeekBar playback={playback} />
|
||||
|
|
|
@ -47,6 +47,13 @@ export const useVoiceBroadcastPlayback = (playback: VoiceBroadcastPlayback) => {
|
|||
d => setDuration(d / 1000),
|
||||
);
|
||||
|
||||
const [position, setPosition] = useState(playback.timeSeconds);
|
||||
useTypedEventEmitter(
|
||||
playback,
|
||||
VoiceBroadcastPlaybackEvent.PositionChanged,
|
||||
p => setPosition(p / 1000),
|
||||
);
|
||||
|
||||
const [liveness, setLiveness] = useState(playback.getLiveness());
|
||||
useTypedEventEmitter(
|
||||
playback,
|
||||
|
@ -57,9 +64,10 @@ export const useVoiceBroadcastPlayback = (playback: VoiceBroadcastPlayback) => {
|
|||
return {
|
||||
duration,
|
||||
liveness: liveness,
|
||||
playbackState,
|
||||
position,
|
||||
room: room,
|
||||
sender: playback.infoEvent.sender,
|
||||
toggle: playbackToggle,
|
||||
playbackState,
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue