1- import './controls .css'
1+ import './commonControls .css'
22
33import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'
44import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp'
55import Box from '@mui/material/Box'
66import Button from '@mui/material/Button'
7- import Icon from '@mui/material/Icon'
8- import IconButton from '@mui/material/IconButton'
97import LinearProgress from '@mui/material/LinearProgress'
108import Slider from '@mui/material/Slider'
119import Typography from '@mui/material/Typography'
12- import React , { useEffect , useState } from 'react'
10+ import React , { useState } from 'react'
1311
1412import { formatDurationTime } from '../../helper'
13+ import { MediaIconButton } from './mediaIconButton'
1514
16- interface MediaIconButtonProps {
17- onClick : ( ) => void
18- action :
19- | 'play'
20- | 'pause'
21- | 'forward'
22- | 'replay'
23- | 'volumeUp'
24- | 'volumeOff'
25- | 'pictureInPicture'
26- | 'pictureInPictureExit'
27- | 'fullscreen'
28- | 'fullscreenExit'
29- | 'captionsOn'
30- | 'captionsOff'
31- className ?: string
32- color ?: string
33- }
34-
35- interface MediaControls {
15+ export interface MediaControls {
3616 mediaElement : HTMLMediaElement
3717 color ?: string
3818}
@@ -43,54 +23,12 @@ interface Toggle {
4323 color ?: string
4424}
4525
46- interface FullscreenToggleProps {
47- element : HTMLElement
48- color ?: string
49- }
50-
5126interface MoveTenSecondsButtonProps extends MediaControls {
5227 movement : 'replay' | 'forward'
5328}
5429
5530const percentMultiple = 100
5631
57- export function MediaIconButton ( props : MediaIconButtonProps ) {
58- const controls = {
59- play : { symbol : 'play_circle' , label : 'play' } ,
60- pause : { symbol : 'pause_circle' , label : 'pause' } ,
61- forward : { symbol : 'forward_10' , label : 'forward ten seconds' } ,
62- replay : { symbol : 'replay_10' , label : 'replay ten seconds' } ,
63- volumeUp : { symbol : 'volume_up' , label : 'mute' } ,
64- volumeOff : { symbol : 'volume_off' , label : 'unmute' } ,
65- pictureInPicture : {
66- symbol : 'picture_in_picture' ,
67- label : 'picture in picture' ,
68- } ,
69- pictureInPictureExit : {
70- symbol : 'picture_in_picture_off' ,
71- label : 'exit picture in picture' ,
72- } ,
73- fullscreen : { symbol : 'fullscreen' , label : 'fullscreen' } ,
74- fullscreenExit : { symbol : 'fullscreen_exit' , label : 'exit fullscreen' } ,
75- captionsOn : { symbol : 'closed_caption' , label : 'show captions' } ,
76- captionsOff : { symbol : 'closed_caption_disabled' , label : 'hide captions' } ,
77- }
78- return (
79- < IconButton
80- onClick = { props . onClick }
81- aria-label = { `click to ${ controls [ props . action ] . label } ` }
82- className = { props . className }
83- data-cy = { `${ props . action } -button` }
84- >
85- < Icon sx = { { color : props . color } } >
86- < span className = "material-symbols-rounded" >
87- { controls [ props . action ] . symbol }
88- </ span >
89- </ Icon >
90- </ IconButton >
91- )
92- }
93-
9432export function ProgressSlider ( props : MediaControls ) {
9533 const formattedElapsedTime = formatDurationTime (
9634 props . mediaElement . currentTime
@@ -270,69 +208,6 @@ export function PausePlayToggle(props: MediaControls) {
270208 )
271209}
272210
273- export function PictureInPictureToggle ( props : MediaControls ) {
274- const [ isPictureInPicture , setIsPictureInPicture ] = useState (
275- ! ! document . pictureInPictureElement
276- )
277-
278- const videoElement = props . mediaElement as HTMLVideoElement
279-
280- const action = isPictureInPicture
281- ? 'pictureInPictureExit'
282- : 'pictureInPicture'
283-
284- function handlePictureInPicture ( ) {
285- if ( isPictureInPicture ) {
286- document . exitPictureInPicture ( )
287- } else {
288- videoElement . requestPictureInPicture ( )
289- }
290- }
291-
292- videoElement . onenterpictureinpicture = function ( ) {
293- setIsPictureInPicture ( true )
294- }
295- videoElement . onleavepictureinpicture = function ( ) {
296- setIsPictureInPicture ( false )
297- }
298-
299- return (
300- < MediaIconButton
301- onClick = { handlePictureInPicture }
302- action = { action }
303- color = { props . color }
304- />
305- )
306- }
307-
308- export function FullscreenToggle ( props : FullscreenToggleProps ) {
309- const [ isFullscreen , setIsFullscreen ] = useState ( ! ! document . fullscreenElement )
310-
311- useEffect ( ( ) => {
312- document . addEventListener ( 'fullscreenchange' , ( ) => {
313- setIsFullscreen ( ! isFullscreen )
314- } )
315- } , [ isFullscreen ] )
316-
317- const action = isFullscreen ? 'fullscreenExit' : 'fullscreen'
318-
319- function handleFullscreen ( ) {
320- if ( isFullscreen ) {
321- document . exitFullscreen ( )
322- } else {
323- props . element . requestFullscreen ( )
324- }
325- }
326-
327- return (
328- < MediaIconButton
329- onClick = { handleFullscreen }
330- action = { action }
331- color = { props . color }
332- />
333- )
334- }
335-
336211export function PlaybackRateButton ( props : MediaControls ) {
337212 const [ playbackRate , setPlaybackRate ] = useState (
338213 props . mediaElement . playbackRate
0 commit comments