@grfzhl/vue-hls-player 1.1.5 → 1.1.6
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.
|
@@ -180,7 +180,6 @@ const currentSubtitle = computed(() => {
|
|
|
180
180
|
return subt.lang === "en"
|
|
181
181
|
}
|
|
182
182
|
})
|
|
183
|
-
console.log("current", currentSubtitleLang)
|
|
184
183
|
return current.length ? current[0] : null
|
|
185
184
|
}
|
|
186
185
|
return null
|
|
@@ -312,26 +311,15 @@ function seekVideo(time) {
|
|
|
312
311
|
function prepareVideoPlayer(link) {
|
|
313
312
|
let initiallyLoaded = true;
|
|
314
313
|
if (video.value) {
|
|
315
|
-
console.log("start hls gtest2 ", hls)
|
|
316
|
-
// video.value.src = link;
|
|
317
|
-
// video.value.load()
|
|
318
|
-
|
|
319
314
|
if (hls) {
|
|
315
|
+
hls.detachMedia();
|
|
320
316
|
hls.destroy();
|
|
321
317
|
initiallyLoaded = false;
|
|
322
318
|
}
|
|
323
|
-
console.log("a")
|
|
324
319
|
hls = new Hls();
|
|
325
|
-
console.log("b")
|
|
326
320
|
hls.loadSource(link)
|
|
327
|
-
|
|
328
|
-
|
|
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)
|
|
321
|
+
hls.attachMedia(video.value)
|
|
322
|
+
hls.recoverMediaError()
|
|
335
323
|
|
|
336
324
|
video.value.muted = props.isMuted
|
|
337
325
|
video.value.currentTime = props.progress
|
|
@@ -373,10 +361,8 @@ console.log("attach to ", video.value)
|
|
|
373
361
|
}
|
|
374
362
|
});
|
|
375
363
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
initVideo();
|
|
379
|
-
// }
|
|
364
|
+
setInterval(checkTrackModeChanges, 100);
|
|
365
|
+
initVideo();
|
|
380
366
|
}
|
|
381
367
|
}
|
|
382
368
|
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
</style>
|
|
112
112
|
|
|
113
113
|
<script setup>
|
|
114
|
-
import { onMounted, watch, ref } from 'vue';
|
|
114
|
+
import { onMounted, watch, ref, nextTick } from 'vue';
|
|
115
115
|
|
|
116
116
|
const props = defineProps({
|
|
117
117
|
subtitle: {
|
|
@@ -137,11 +137,11 @@ const subtitlesContainer = ref(null);
|
|
|
137
137
|
const vttCues = ref([]);
|
|
138
138
|
const txtCues = ref([]);
|
|
139
139
|
const currentCue = ref(null);
|
|
140
|
+
const videoCursor = ref(0);
|
|
140
141
|
|
|
141
142
|
|
|
142
143
|
const loadCues = async () => {
|
|
143
144
|
if (props.subtitle) {
|
|
144
|
-
console.log("load subtittles", props.subtitle.link)
|
|
145
145
|
const vttPath = props.subtitle.link;
|
|
146
146
|
const txtPath = vttPath.replace(/\.vtt$/, '.txt');
|
|
147
147
|
vttCues.value = await parseVTT(vttPath);
|
|
@@ -159,8 +159,9 @@ watch(
|
|
|
159
159
|
);
|
|
160
160
|
|
|
161
161
|
const onTimeUpdate = (video) => {
|
|
162
|
-
if (video) {
|
|
162
|
+
if (video && txtCues?.value?.length && vttCues?.value?.length) {
|
|
163
163
|
const currentTime = video.currentTime;
|
|
164
|
+
videoCursor.value = currentTime;
|
|
164
165
|
props.cursor = currentTime;
|
|
165
166
|
highlightActiveCue(currentTime);
|
|
166
167
|
checkCurrentCue(currentTime);
|
|
@@ -196,7 +197,7 @@ function seekTo(time) {
|
|
|
196
197
|
* @param txtCue
|
|
197
198
|
*/
|
|
198
199
|
function isTxtCueActive(txtCue) {
|
|
199
|
-
return
|
|
200
|
+
return videoCursor.value >= txtCue.start && videoCursor.value <= txtCue.end;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
/**
|
|
@@ -219,10 +220,11 @@ function isWordActive(txtCue, word, wordIndex, txtIndex, currentCue) {
|
|
|
219
220
|
return false;
|
|
220
221
|
}
|
|
221
222
|
|
|
222
|
-
function checkCurrentCue(currentCursor) {
|
|
223
|
-
Array.from(vttCues.value).forEach((a, index) => {
|
|
224
|
-
if(
|
|
223
|
+
async function checkCurrentCue(currentCursor) {
|
|
224
|
+
Array.from(vttCues.value).forEach(async (a, index) => {
|
|
225
|
+
if(videoCursor.value >= a.start && videoCursor.value <= a.end) {
|
|
225
226
|
currentCue.value = a.text
|
|
227
|
+
await nextTick()
|
|
226
228
|
}
|
|
227
229
|
});
|
|
228
230
|
}
|
|
@@ -236,7 +238,7 @@ async function parseVTT(fileUrl) {
|
|
|
236
238
|
const response = await fetch(fileUrl);
|
|
237
239
|
const text = await response.text();
|
|
238
240
|
const cues = [];
|
|
239
|
-
const lines = text.split('\n');
|
|
241
|
+
const lines = text.replace(/\r/g, '').split('\n');
|
|
240
242
|
let cue = null;
|
|
241
243
|
|
|
242
244
|
for (let i = 0; i < lines.length; i++) {
|