customvidplayer 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,7 @@ declare namespace VideoPlayer {
|
|
11
11
|
const sections: PropTypes.Validator<(PropTypes.InferProps<{
|
12
12
|
name: PropTypes.Validator<string>;
|
13
13
|
timestamp: PropTypes.Validator<number>;
|
14
|
+
color: PropTypes.Requireable<string>;
|
14
15
|
}> | null | undefined)[]>;
|
15
16
|
const onSectionChange: PropTypes.Requireable<(...args: any[]) => any>;
|
16
17
|
const theme: PropTypes.Requireable<object>;
|
@@ -61,6 +61,9 @@ var VideoPlayer = function VideoPlayer(_a) {
|
|
61
61
|
var _b = (0, react_1.useState)(0),
|
62
62
|
currentSectionIndex = _b[0],
|
63
63
|
setCurrentSectionIndex = _b[1];
|
64
|
+
var _c = (0, react_1.useState)(false),
|
65
|
+
isPlaying = _c[0],
|
66
|
+
setIsPlaying = _c[1];
|
64
67
|
var skipToNextSection = function skipToNextSection() {
|
65
68
|
if (currentSectionIndex < sections.length - 1) {
|
66
69
|
var nextSection = sections[currentSectionIndex + 1];
|
@@ -80,25 +83,57 @@ var VideoPlayer = function VideoPlayer(_a) {
|
|
80
83
|
if (onSectionChange) onSectionChange(currentSection);
|
81
84
|
}
|
82
85
|
};
|
86
|
+
var playVideo = function playVideo() {
|
87
|
+
videoRef.current.play();
|
88
|
+
setIsPlaying(true);
|
89
|
+
};
|
90
|
+
var pauseVideo = function pauseVideo() {
|
91
|
+
videoRef.current.pause();
|
92
|
+
setIsPlaying(false);
|
93
|
+
};
|
94
|
+
var skipForward = function skipForward() {
|
95
|
+
videoRef.current.currentTime += 10;
|
96
|
+
};
|
83
97
|
return react_1["default"].createElement("div", {
|
84
98
|
className: "video-player",
|
85
99
|
style: __assign({}, theme)
|
86
100
|
}, react_1["default"].createElement("video", {
|
87
101
|
src: videoSrc,
|
88
|
-
controls:
|
102
|
+
controls: false,
|
89
103
|
ref: videoRef,
|
90
104
|
onTimeUpdate: handleTimeUpdate,
|
91
105
|
className: "video-element"
|
92
|
-
}), react_1["default"].createElement("
|
106
|
+
}), react_1["default"].createElement("div", {
|
107
|
+
className: "bottom-bar",
|
108
|
+
style: {
|
109
|
+
backgroundColor: theme.bottomBarColor || '#000'
|
110
|
+
}
|
111
|
+
}, react_1["default"].createElement("button", {
|
112
|
+
onClick: isPlaying ? pauseVideo : playVideo
|
113
|
+
}, isPlaying ? 'Pause' : 'Play'), react_1["default"].createElement("button", {
|
114
|
+
onClick: skipForward
|
115
|
+
}, "Skip 10s"), react_1["default"].createElement("button", {
|
93
116
|
onClick: skipToNextSection,
|
94
117
|
className: "skip-button"
|
95
|
-
}, "Skip"))
|
118
|
+
}, "Skip")), react_1["default"].createElement("div", {
|
119
|
+
className: "progress-bar"
|
120
|
+
}, sections.map(function (section, index) {
|
121
|
+
return react_1["default"].createElement("div", {
|
122
|
+
key: index,
|
123
|
+
className: "section-indicator",
|
124
|
+
style: {
|
125
|
+
left: "".concat(section.timestamp / videoRef.current.duration * 100, "%"),
|
126
|
+
backgroundColor: section.color || '#007bff'
|
127
|
+
}
|
128
|
+
}, section.name);
|
129
|
+
})));
|
96
130
|
};
|
97
131
|
VideoPlayer.propTypes = {
|
98
132
|
videoSrc: prop_types_1["default"].string.isRequired,
|
99
133
|
sections: prop_types_1["default"].arrayOf(prop_types_1["default"].shape({
|
100
134
|
name: prop_types_1["default"].string.isRequired,
|
101
|
-
timestamp: prop_types_1["default"].number.isRequired
|
135
|
+
timestamp: prop_types_1["default"].number.isRequired,
|
136
|
+
color: prop_types_1["default"].string
|
102
137
|
})).isRequired,
|
103
138
|
onSectionChange: prop_types_1["default"].func,
|
104
139
|
theme: prop_types_1["default"].object
|
package/package.json
CHANGED
@@ -5,6 +5,7 @@ import "./../styles/defaultTheme.css";
|
|
5
5
|
const VideoPlayer = ({ videoSrc, sections, onSectionChange, theme }) => {
|
6
6
|
const videoRef = useRef(null);
|
7
7
|
const [currentSectionIndex, setCurrentSectionIndex] = useState(0);
|
8
|
+
const [isPlaying, setIsPlaying] = useState(false);
|
8
9
|
|
9
10
|
const skipToNextSection = () => {
|
10
11
|
if (currentSectionIndex < sections.length - 1) {
|
@@ -30,18 +31,52 @@ const VideoPlayer = ({ videoSrc, sections, onSectionChange, theme }) => {
|
|
30
31
|
}
|
31
32
|
};
|
32
33
|
|
34
|
+
const playVideo = () => {
|
35
|
+
videoRef.current.play();
|
36
|
+
setIsPlaying(true);
|
37
|
+
};
|
38
|
+
|
39
|
+
const pauseVideo = () => {
|
40
|
+
videoRef.current.pause();
|
41
|
+
setIsPlaying(false);
|
42
|
+
};
|
43
|
+
|
44
|
+
const skipForward = () => {
|
45
|
+
videoRef.current.currentTime += 10;
|
46
|
+
};
|
47
|
+
|
33
48
|
return (
|
34
49
|
<div className="video-player" style={{ ...theme }}>
|
35
50
|
<video
|
36
51
|
src={videoSrc}
|
37
|
-
controls
|
52
|
+
controls={false}
|
38
53
|
ref={videoRef}
|
39
54
|
onTimeUpdate={handleTimeUpdate}
|
40
55
|
className="video-element"
|
41
56
|
/>
|
42
|
-
<
|
43
|
-
|
44
|
-
|
57
|
+
<div className="bottom-bar" style={{ backgroundColor: theme.bottomBarColor || '#000' }}>
|
58
|
+
<button onClick={isPlaying ? pauseVideo : playVideo}>
|
59
|
+
{isPlaying ? 'Pause' : 'Play'}
|
60
|
+
</button>
|
61
|
+
<button onClick={skipForward}>Skip 10s</button>
|
62
|
+
<button onClick={skipToNextSection} className="skip-button">
|
63
|
+
Skip
|
64
|
+
</button>
|
65
|
+
</div>
|
66
|
+
<div className="progress-bar">
|
67
|
+
{sections.map((section, index) => (
|
68
|
+
<div
|
69
|
+
key={index}
|
70
|
+
className="section-indicator"
|
71
|
+
style={{
|
72
|
+
left: `${(section.timestamp / videoRef.current.duration) * 100}%`,
|
73
|
+
backgroundColor: section.color || '#007bff',
|
74
|
+
}}
|
75
|
+
>
|
76
|
+
{section.name}
|
77
|
+
</div>
|
78
|
+
))}
|
79
|
+
</div>
|
45
80
|
</div>
|
46
81
|
);
|
47
82
|
};
|
@@ -52,6 +87,7 @@ VideoPlayer.propTypes = {
|
|
52
87
|
PropTypes.shape({
|
53
88
|
name: PropTypes.string.isRequired,
|
54
89
|
timestamp: PropTypes.number.isRequired,
|
90
|
+
color: PropTypes.string,
|
55
91
|
})
|
56
92
|
).isRequired,
|
57
93
|
onSectionChange: PropTypes.func,
|
@@ -27,4 +27,24 @@
|
|
27
27
|
margin: 5px 0;
|
28
28
|
color: #007bff;
|
29
29
|
}
|
30
|
+
|
31
|
+
.bottom-bar {
|
32
|
+
display: flex;
|
33
|
+
justify-content: space-between;
|
34
|
+
padding: 10px;
|
35
|
+
}
|
36
|
+
|
37
|
+
.progress-bar {
|
38
|
+
position: relative;
|
39
|
+
height: 5px;
|
40
|
+
background: #ccc;
|
41
|
+
margin-top: 5px;
|
42
|
+
}
|
43
|
+
|
44
|
+
.section-indicator {
|
45
|
+
position: absolute;
|
46
|
+
width: 5px;
|
47
|
+
height: 100%;
|
48
|
+
background: #007bff; /* Default color */
|
49
|
+
}
|
30
50
|
|