@grfzhl/vue-hls-player 1.1.3 → 1.1.4

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.
@@ -58,6 +58,7 @@
58
58
  </div>
59
59
  <slot name="before-transcripts"></slot>
60
60
  <SubtitleBlock
61
+ ref="transcriptRef"
61
62
  :subtitle="currentSubtitle"
62
63
  :cursor="videoCursor"
63
64
  :showTranscriptBlock="showTranscriptBlock"
@@ -144,6 +145,7 @@ const orientation = ref(null)
144
145
  const autoHideIntroTitle = ref(false);
145
146
  const initialPlayButton = ref(false);
146
147
  const hideInitialPlayButton = ref(false)
148
+ const transcriptRef = ref(null)
147
149
  const link = toRef(props, 'link');
148
150
  const previewImageLink = toRef(props, 'previewImageLink');
149
151
  let currentTime = 0
@@ -289,6 +291,11 @@ function updateCurrentTime() {
289
291
  if(!video.value.paused) {
290
292
  initialPlayButton.value = false;
291
293
  }
294
+
295
+ // update transcripts
296
+ if(transcriptRef && video) {
297
+ transcriptRef.value.onTimeUpdate(video.value)
298
+ }
292
299
  }
293
300
 
294
301
  function toggleTranscript() {
@@ -143,7 +143,6 @@ const loadCues = async () => {
143
143
  if (props.subtitle) {
144
144
  const vttPath = props.subtitle.link;
145
145
  const txtPath = vttPath.replace(/\.vtt$/, '.txt');
146
-
147
146
  vttCues.value = await parseVTT(vttPath);
148
147
  txtCues.value = await parseTXT(txtPath);
149
148
  }
@@ -158,14 +157,14 @@ watch(
158
157
  }
159
158
  );
160
159
 
161
- watch(
162
- () => props.cursor,
163
- (currentTime) => {
164
- console.log("cursor watch", currentTime)
160
+ const onTimeUpdate = (video) => {
161
+ if (video) {
162
+ const currentTime = video.currentTime;
163
+ props.cursor = currentTime;
165
164
  highlightActiveCue(currentTime);
166
- checkCurrentCue(currentTime)
165
+ checkCurrentCue(currentTime);
167
166
  }
168
- );
167
+ };
169
168
 
170
169
  /**
171
170
  * highlgiht the current transcript part
@@ -223,7 +222,6 @@ function isWordActive(txtCue, word, wordIndex, txtIndex) {
223
222
 
224
223
  function checkCurrentCue(currentCursor) {
225
224
  Array.from(vttCues.value).forEach((a, index) => {
226
- console.log("current cue", a)
227
225
  if(currentCursor >= a.start && currentCursor <= a.end) {
228
226
  currentCue.value = a.text
229
227
  }
@@ -322,4 +320,6 @@ function secondsToTime(seconds) {
322
320
  const pad = (num) => String(num).padStart(2, '0');
323
321
  return `${pad(hours)}:${pad(minutes)}:${pad(secs)}`;
324
322
  }
323
+
324
+ defineExpose({ onTimeUpdate });
325
325
  </script>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@grfzhl/vue-hls-player",
3
3
  "private": false,
4
- "version": "1.1.3",
4
+ "version": "1.1.4",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"