Skip to content

Commit 2f316ff

Browse files
Video player: Playback status and handle Map to time (#214)
* Add isPlaying status and handle map to simulation time (no playback controls) * Shorten info string slightly * Add variable for hiding playback
1 parent b0d09b1 commit 2f316ff

3 files changed

Lines changed: 39 additions & 21 deletions

File tree

public/locales/en/components.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@
192192
},
193193
"info-box": {
194194
"description": "Properties for controlling video playback."
195-
}
195+
},
196+
"mapped-to-time-info": "Playback is mapped to simulation time."
196197
}
197198
},
198199
"qrcode": {

src/components/PropertyOwner/Custom/VideoPlayer/VideoPlayer.tsx

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Grid,
66
Group,
77
MantineStyleProps,
8+
Paper,
89
Text,
910
ThemeIcon,
1011
Tooltip
@@ -22,8 +23,11 @@ import {
2223
RepeatOffIcon,
2324
ReplayIcon,
2425
SoundIcon,
25-
SoundOffIcon
26+
SoundOffIcon,
27+
TimeIcon
2628
} from '@/icons/icons';
29+
import styles from '@/theme/global.module.css';
30+
import { IconSize } from '@/types/enums';
2731
import { Uri } from '@/types/types';
2832

2933
interface Props extends MantineStyleProps {
@@ -55,10 +59,30 @@ export function VideoPlayer({ uri, ...styleProps }: Props) {
5559
playAudioUri
5660
);
5761

62+
const [isPlaying] = useProperty('BoolProperty', `${uri}.IsPlaying`);
63+
const [startTime] = useProperty('StringProperty', `${uri}.StartTime`);
64+
const [endTime] = useProperty('StringProperty', `${uri}.EndTime`);
65+
5866
if (!propertyOwner) {
5967
throw Error(`No property owner found for uri: ${uri}`);
6068
}
6169

70+
const shouldHidePlaybackControls = Boolean(startTime) || Boolean(endTime);
71+
72+
if (shouldHidePlaybackControls) {
73+
// This video player is mapped to time
74+
return (
75+
<Paper ml={'xs'} p={'xs'}>
76+
<Group wrap={'nowrap'} gap={'xs'}>
77+
<ThemeIcon variant={'subtle'} size={'xs'}>
78+
<TimeIcon size={IconSize.xs} />
79+
</ThemeIcon>
80+
<Text size={'sm'}>{t('mapped-to-time-info')}</Text>
81+
</Group>
82+
</Paper>
83+
);
84+
}
85+
6286
// Data for the different properties that the controls represent, to show in the
6387
// info box
6488
const propertyData = [
@@ -76,24 +100,17 @@ export function VideoPlayer({ uri, ...styleProps }: Props) {
76100
return (
77101
<Group pl={'xs'} wrap={'nowrap'} {...styleProps}>
78102
<Group gap={'xs'} py={'xs'}>
79-
<ActionIcon.Group>
80-
<Tooltip label={t('play-button.tooltip')}>
81-
<ActionIcon
82-
onClick={() => triggerPlay(null)}
83-
aria-label={t('play-button.aria-label')}
84-
>
85-
<PlayIcon />
86-
</ActionIcon>
87-
</Tooltip>
88-
<Tooltip label={t('pause-button.tooltip')}>
89-
<ActionIcon
90-
onClick={() => triggerPause(null)}
91-
aria-label={t('pause-button.aria-label')}
92-
>
93-
<PauseIcon />
94-
</ActionIcon>
95-
</Tooltip>
96-
</ActionIcon.Group>
103+
<Tooltip label={isPlaying ? t('pause-button.tooltip') : t('play-button.tooltip')}>
104+
<ActionIcon
105+
variant={isPlaying ? 'filled' : 'default'}
106+
onClick={() => (isPlaying ? triggerPause(null) : triggerPlay(null))}
107+
aria-label={
108+
isPlaying ? t('pause-button.aria-label') : t('play-button.aria-label')
109+
}
110+
>
111+
{isPlaying ? <PauseIcon className={styles.blinking} /> : <PlayIcon />}
112+
</ActionIcon>
113+
</Tooltip>
97114
<Tooltip label={t('restart-button.tooltip')}>
98115
<ActionIcon
99116
onClick={() => triggerGoToStart(null)}

src/icons/icons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export {
2727
export { GoBrowser as BrowserIcon } from 'react-icons/go';
2828
export { GoMoveToEnd as GoToEnd, GoMoveToStart as GoToStart } from 'react-icons/go';
2929
export { ImSphere as GridSphereIcon } from 'react-icons/im';
30-
export { IoMdGlobe as GlobeIcon } from 'react-icons/io';
30+
export { IoMdGlobe as GlobeIcon, IoMdTime as TimeIcon } from 'react-icons/io';
3131
export {
3232
IoInformationCircleOutline as InformationCircleOutlineIcon,
3333
IoInformation as InformationIcon,

0 commit comments

Comments
 (0)