customvidplayer 0.0.15 → 0.0.17

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.
@@ -73,14 +73,16 @@ var VideoPlayer = function VideoPlayer(_a) {
73
73
  }
74
74
  };
75
75
  var handleTimeUpdate = function handleTimeUpdate() {
76
- var currentTime = videoRef.current.currentTime;
77
- var currentSection = sections.find(function (section, index) {
78
- return currentTime >= section.timestamp && (index === sections.length - 1 || currentTime < sections[index + 1].timestamp);
79
- });
80
- if (currentSection && sections[currentSectionIndex] !== currentSection) {
81
- var newIndex = sections.indexOf(currentSection);
82
- setCurrentSectionIndex(newIndex);
83
- if (onSectionChange) onSectionChange(currentSection);
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.currentTime += 10;
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,6 +1,6 @@
1
1
  {
2
2
  "name": "customvidplayer",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "Customizable video player with section navigation and theming.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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
- const currentTime = videoRef.current.currentTime;
21
- const currentSection = sections.find(
22
- (section, index) =>
23
- currentTime >= section.timestamp &&
24
- (index === sections.length - 1 || currentTime < sections[index + 1].timestamp)
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
- if (currentSection && sections[currentSectionIndex] !== currentSection) {
28
- const newIndex = sections.indexOf(currentSection);
29
- setCurrentSectionIndex(newIndex);
30
- if (onSectionChange) onSectionChange(currentSection);
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.currentTime += 10;
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
  >