11"use client" ;
2- import React , { useState , useRef } from "react" ;
2+ import React , { useState } from "react" ;
33import { IconButton , Slider , Menu , MenuItem } from "@mui/material" ;
44import PlayArrowIcon from "@mui/icons-material/PlayArrow" ;
55import PauseIcon from "@mui/icons-material/Pause" ;
@@ -13,7 +13,7 @@ export default function Scrubber({
1313 restart,
1414 setPlaybackSpeed,
1515 moveToTime,
16- duration
16+ duration,
1717} : {
1818 time : number ;
1919 play : boolean ;
@@ -27,6 +27,7 @@ export default function Scrubber({
2727 const [ selectedSpeed , setSelectedSpeed ] = useState < number > ( 1 ) ;
2828 const speedOptions = [ 0.5 , 1 , 1.5 , 2 , 3 ] ;
2929 const open = Boolean ( anchorEl ) ;
30+ const [ isDragging , setIsDragging ] = useState < boolean > ( false ) ;
3031 const handleClick = ( event : React . MouseEvent < HTMLButtonElement > ) => {
3132 setAnchorEl ( event . currentTarget ) ;
3233 } ;
@@ -38,32 +39,64 @@ export default function Scrubber({
3839 setPlaybackSpeed ( speed ) ;
3940 handleClose ( ) ;
4041 } ;
41- const handleSliderChange = ( _ : Event , newValue : number | number [ ] ) => {
42- if ( typeof newValue === "number" ) {
43- moveToTime ( newValue ) ;
44- }
42+ const handleSliderChange = ( _ : Event , newValue : number ) => {
43+ moveToTime ( newValue ) ;
4544 } ;
45+ const handleSliderChangeCommitted = ( ) => {
46+ setIsDragging ( false ) ;
47+ }
4648 const formatDuration = ( time : number ) => {
4749 const minutes = Math . floor ( time / 60 ) ;
4850 const seconds = Math . floor ( time % 60 ) ;
49- return `${ minutes < 10 ? "0" : "" } ${ minutes } :${ seconds < 10 ? "0" : "" } ${ seconds } ` ;
50- }
51+ return `${ minutes < 10 ? "0" : "" } ${ minutes } :${
52+ seconds < 10 ? "0" : ""
53+ } ${ seconds } `;
54+ } ;
55+ const handleContextMenu = ( event : React . MouseEvent ) => {
56+ event . preventDefault ( ) ;
57+ } ;
5158 return (
52- < div className = "px-5 fixed bottom-5 left-1/6 h-20 w-2/3 bg-black/40 text-white shadow-lg rounded-full flex justify-center items-center" >
53- < IconButton size = "large" onClick = { togglePlay } >
59+ < div
60+ className = "px-5 fixed bottom-5 left-1/6 h-20 w-2/3 bg-black/40 text-white shadow-lg rounded-full flex justify-center items-center"
61+ onContextMenu = { handleContextMenu }
62+ >
63+ < IconButton
64+ size = "large"
65+ onClick = { togglePlay }
66+ sx = { { marginRight : "20px" , color : "white" } }
67+ >
5468 { play ? (
5569 < PauseIcon fontSize = "inherit" />
5670 ) : (
5771 < PlayArrowIcon fontSize = "inherit" />
5872 ) }
5973 </ IconButton >
60- < div className = "w-2/3 flex items-center" >
61- < div > { time < duration ? formatDuration ( time ) : formatDuration ( duration ) } </ div >
62- < Slider min = { 0 } max = { duration } step = { 0.000001 } className = "mx-8" disabled = { duration === 0 } onChange = { handleSliderChange } value = { time } />
74+ < div className = "w-2/3 flex items-center select-none text-xl" >
75+ < div >
76+ { time < duration
77+ ? formatDuration ( time )
78+ : formatDuration ( duration ) }
79+ </ div >
80+ < Slider
81+ key = { isDragging ? undefined : Math . floor ( time * 100 ) }
82+ min = { 0 }
83+ max = { duration }
84+ step = { 0.02 }
85+ className = "mx-8"
86+ disabled = { duration === 0 }
87+ onChange = { handleSliderChange }
88+ onMouseDown = { ( ) => setIsDragging ( true ) }
89+ onChangeCommitted = { handleSliderChangeCommitted }
90+ value = { time }
91+ />
6392 < div > { formatDuration ( duration ) } </ div >
6493 </ div >
65- < div >
66- < IconButton size = "large" onClick = { handleClick } >
94+ < div className = "ml-5 flex flex-nowrap" >
95+ < IconButton
96+ size = "large"
97+ onClick = { handleClick }
98+ sx = { { color : "white" } }
99+ >
67100 < SpeedIcon fontSize = "inherit" />
68101 </ IconButton >
69102 < Menu
@@ -89,7 +122,10 @@ export default function Scrubber({
89122 </ MenuItem >
90123 ) ) }
91124 </ Menu >
92- < IconButton size = "large" >
125+ < IconButton
126+ size = "large"
127+ sx = { { marginLeft : "20px" , color : "white" } }
128+ >
93129 < RefreshIcon fontSize = "inherit" onClick = { restart } />
94130 </ IconButton >
95131 </ div >
0 commit comments