@grfzhl/vue-hls-player 1.1.4 → 1.1.5

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.
@@ -144,21 +144,17 @@ const isFullscreen = ref(false);
144
144
  const orientation = ref(null)
145
145
  const autoHideIntroTitle = ref(false);
146
146
  const initialPlayButton = ref(false);
147
- const hideInitialPlayButton = ref(false)
148
- const transcriptRef = ref(null)
149
- const link = toRef(props, 'link');
147
+ const hideInitialPlayButton = ref(false);
148
+ const transcriptRef = ref(null);
150
149
  const previewImageLink = toRef(props, 'previewImageLink');
150
+ const link = toRef(props, 'link');
151
151
  let currentTime = 0
152
152
  let hls = null
153
153
 
154
154
  const videoElement = defineModel()
155
155
 
156
156
  onMounted(() => {
157
- prepareVideoPlayer()
158
- })
159
-
160
- onUpdated(() => {
161
-
157
+ prepareVideoPlayer(props.link)
162
158
  })
163
159
 
164
160
  onUnmounted(() => {
@@ -178,8 +174,13 @@ const mutedAttr = computed(() => {
178
174
  const currentSubtitle = computed(() => {
179
175
  if(props.subtitles) {
180
176
  const current = props.subtitles.filter((subt) => {
181
- return subt.lang === currentSubtitleLang.value
177
+ if(currentSubtitleLang.value) {
178
+ return subt.lang === currentSubtitleLang.value
179
+ } else {
180
+ return subt.lang === "en"
181
+ }
182
182
  })
183
+ console.log("current", currentSubtitleLang)
183
184
  return current.length ? current[0] : null
184
185
  }
185
186
  return null
@@ -195,10 +196,11 @@ watch([props, videoElement], (a) => {
195
196
  }
196
197
  })
197
198
 
198
- watch(link, (newLink, oldLink) => {
199
+ watch(
200
+ () => props.link,
201
+ (newLink, oldLink) => {
199
202
  if (newLink !== oldLink) {
200
- console.log("prepare new src " + newLink)
201
- prepareVideoPlayer();
203
+ prepareVideoPlayer(newLink);
202
204
  }
203
205
  })
204
206
 
@@ -307,15 +309,29 @@ function seekVideo(time) {
307
309
  video.value.play()
308
310
  }
309
311
 
310
- function prepareVideoPlayer() {
312
+ function prepareVideoPlayer(link) {
313
+ let initiallyLoaded = true;
311
314
  if (video.value) {
315
+ console.log("start hls gtest2 ", hls)
316
+ // video.value.src = link;
317
+ // video.value.load()
318
+
312
319
  if (hls) {
313
320
  hls.destroy();
321
+ initiallyLoaded = false;
314
322
  }
323
+ console.log("a")
315
324
  hls = new Hls();
316
- let stream = props.link
317
- hls.loadSource(stream)
318
- hls.attachMedia(video.value)
325
+ console.log("b")
326
+ hls.loadSource(link)
327
+ console.log("c", video.value)
328
+ // const shadowRoot = video.value?.shadowRoot;
329
+ // const videoElement = shadowRoot?.querySelector("video");
330
+ // const videoElement = document.querySelector("video.hls-player")[0]
331
+ // if(initiallyLoaded) {
332
+ hls.attachMedia(video.value)
333
+ // }
334
+ console.log("attach to ", video.value)
319
335
 
320
336
  video.value.muted = props.isMuted
321
337
  video.value.currentTime = props.progress
@@ -357,8 +373,10 @@ function prepareVideoPlayer() {
357
373
  }
358
374
  });
359
375
  }
360
- setInterval(checkTrackModeChanges, 100);
361
- initVideo();
376
+ // if(!initiallyLoaded) {
377
+ setInterval(checkTrackModeChanges, 100);
378
+ initVideo();
379
+ // }
362
380
  }
363
381
  }
364
382
 
@@ -28,7 +28,7 @@
28
28
  <span
29
29
  v-for="(word, wordIndex) in txtCue.dialog[0].text.split('')"
30
30
  :key="wordIndex"
31
- :class="{ 'active-word': isWordActive(txtCue, word, wordIndex, index) && isTxtCueActive(txtCue) }"
31
+ :class="{ 'active-word': isWordActive(txtCue, word, wordIndex, index, currentCue) && isTxtCueActive(txtCue) }"
32
32
  >
33
33
  {{ word }}
34
34
  </span>
@@ -141,6 +141,7 @@ const currentCue = ref(null);
141
141
 
142
142
  const loadCues = async () => {
143
143
  if (props.subtitle) {
144
+ console.log("load subtittles", props.subtitle.link)
144
145
  const vttPath = props.subtitle.link;
145
146
  const txtPath = vttPath.replace(/\.vtt$/, '.txt');
146
147
  vttCues.value = await parseVTT(vttPath);
@@ -206,14 +207,12 @@ function isTxtCueActive(txtCue) {
206
207
  * @param wordIndex
207
208
  * @param txtIndex
208
209
  */
209
- function isWordActive(txtCue, word, wordIndex, txtIndex) {
210
- console.log("check word active ", txtCue, word, wordIndex, currentCue.value)
211
- if(!currentCue.value || !word || !txtCue) {
210
+ function isWordActive(txtCue, word, wordIndex, txtIndex, currentCue) {
211
+ if(!currentCue || !word || !txtCue) {
212
212
  return false
213
213
  }
214
- const startPos = txtCue.dialog[0].text.indexOf(currentCue.value)
215
- const endPos = startPos + currentCue.value.length
216
- console.log("can word marked", startPos, endPos, wordIndex)
214
+ const startPos = txtCue.dialog[0].text.indexOf(currentCue)
215
+ const endPos = startPos + currentCue.length
217
216
  if(wordIndex >= startPos && wordIndex < endPos) {
218
217
  return true;
219
218
  }
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.4",
4
+ "version": "1.1.5",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"