customvidplayer 0.0.15 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/VideoPlayer.js +14 -10
- package/package.json +1 -1
- package/src/components/VideoPlayer.js +17 -13
@@ -73,14 +73,16 @@ var VideoPlayer = function VideoPlayer(_a) {
|
|
73
73
|
}
|
74
74
|
};
|
75
75
|
var handleTimeUpdate = function handleTimeUpdate() {
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
76
|
+
if (videoRef.current) {
|
77
|
+
var currentTime_1 = videoRef.current.currentTime;
|
78
|
+
var currentSection = sections.find(function (section, index) {
|
79
|
+
return currentTime_1 >= section.timestamp && (index === sections.length - 1 || currentTime_1 < sections[index + 1].timestamp);
|
80
|
+
});
|
81
|
+
if (currentSection && sections[currentSectionIndex] !== currentSection) {
|
82
|
+
var newIndex = sections.indexOf(currentSection);
|
83
|
+
setCurrentSectionIndex(newIndex);
|
84
|
+
if (onSectionChange) onSectionChange(currentSection);
|
85
|
+
}
|
84
86
|
}
|
85
87
|
};
|
86
88
|
var playVideo = function playVideo() {
|
@@ -92,7 +94,9 @@ var VideoPlayer = function VideoPlayer(_a) {
|
|
92
94
|
setIsPlaying(false);
|
93
95
|
};
|
94
96
|
var skipForward = function skipForward() {
|
95
|
-
videoRef.current
|
97
|
+
if (videoRef.current) {
|
98
|
+
videoRef.current.currentTime += 10;
|
99
|
+
}
|
96
100
|
};
|
97
101
|
return react_1["default"].createElement("div", {
|
98
102
|
className: "video-player",
|
@@ -122,7 +126,7 @@ var VideoPlayer = function VideoPlayer(_a) {
|
|
122
126
|
key: index,
|
123
127
|
className: "section-indicator",
|
124
128
|
style: {
|
125
|
-
left: "".concat(section.timestamp / videoRef.current.duration * 100, "%"),
|
129
|
+
left: videoRef.current ? "".concat(section.timestamp / videoRef.current.duration * 100, "%") : '0%',
|
126
130
|
backgroundColor: section.color || '#007bff'
|
127
131
|
}
|
128
132
|
}, section.name);
|
package/package.json
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useState, useRef } from "react";
|
1
|
+
import React, { useState, useRef, useEffect } from "react";
|
2
2
|
import PropTypes from "prop-types";
|
3
3
|
import "./../styles/defaultTheme.css";
|
4
4
|
|
@@ -17,17 +17,19 @@ const VideoPlayer = ({ videoSrc, sections, onSectionChange, theme }) => {
|
|
17
17
|
};
|
18
18
|
|
19
19
|
const handleTimeUpdate = () => {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
if (videoRef.current) {
|
21
|
+
const currentTime = videoRef.current.currentTime;
|
22
|
+
const currentSection = sections.find(
|
23
|
+
(section, index) =>
|
24
|
+
currentTime >= section.timestamp &&
|
25
|
+
(index === sections.length - 1 || currentTime < sections[index + 1].timestamp)
|
26
|
+
);
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
if (currentSection && sections[currentSectionIndex] !== currentSection) {
|
29
|
+
const newIndex = sections.indexOf(currentSection);
|
30
|
+
setCurrentSectionIndex(newIndex);
|
31
|
+
if (onSectionChange) onSectionChange(currentSection);
|
32
|
+
}
|
31
33
|
}
|
32
34
|
};
|
33
35
|
|
@@ -42,7 +44,9 @@ const VideoPlayer = ({ videoSrc, sections, onSectionChange, theme }) => {
|
|
42
44
|
};
|
43
45
|
|
44
46
|
const skipForward = () => {
|
45
|
-
videoRef.current
|
47
|
+
if (videoRef.current) {
|
48
|
+
videoRef.current.currentTime += 10;
|
49
|
+
}
|
46
50
|
};
|
47
51
|
|
48
52
|
return (
|
@@ -69,7 +73,7 @@ const VideoPlayer = ({ videoSrc, sections, onSectionChange, theme }) => {
|
|
69
73
|
key={index}
|
70
74
|
className="section-indicator"
|
71
75
|
style={{
|
72
|
-
left: `${(section.timestamp / videoRef.current.duration) * 100}
|
76
|
+
left: videoRef.current ? `${(section.timestamp / videoRef.current.duration) * 100}%` : '0%',
|
73
77
|
backgroundColor: section.color || '#007bff',
|
74
78
|
}}
|
75
79
|
>
|