File size: 1,606 Bytes
2a108da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React, { useState } from 'react';
import { LinearProgress, Box } from '@mui/material';
import './SeekableProgressBar.css';

const SeekableProgressBar = ({ 
  progress, 
  buffer, 
  onSeek,
  width = '100%',
  height = '10px',
  margin = '10px', 
  borderRadios = '10px'
}) => {
  const handleMouseDown = (event) => {
    const progressBar = event.currentTarget;
    const rect = progressBar.getBoundingClientRect();
    const seekPosition = ((event.clientX - rect.left) / rect.width) * 100;
    onSeek(seekPosition);
  };

  const handleMouseMove = (event) => {
    if (isSeeking) {
      const progressBar = event.currentTarget;
      const rect = progressBar.getBoundingClientRect();
      const seekPosition = ((event.clientX - rect.left) / rect.width) * 100;
      onSeek(seekPosition);
    }
  };

  const [isSeeking, setIsSeeking] = useState(false);

  return (
    <Box
      onMouseDown={(event) => {
        setIsSeeking(true);
        handleMouseDown(event);
      }}
      onMouseUp={() => setIsSeeking(false)}
      onMouseLeave={() => setIsSeeking(false)}
      onMouseMove={handleMouseMove}
      sx={{ position: 'relative', width: width }}
    >
      <LinearProgress 
        variant="buffer" 
        value={progress} 
        valueBuffer={buffer}
        sx={{ height: height, margin: margin, borderRadius:borderRadios}} 
      />
      <Box
        sx={{
          position: 'absolute',
          width: '95%',
          height: '100%',
          cursor: 'pointer',
          top: 0,
          left: 0,
        }}
      />
    </Box>
  );
};

export default SeekableProgressBar;