@grfzhl/vue-hls-player 1.1.5 → 1.1.7
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
|
|
@@ -220,7 +219,7 @@ async function startFullscreen() {
|
|
|
220
219
|
try {
|
|
221
220
|
if (vpVideoBlock.requestFullscreen) {
|
|
222
221
|
await vpVideoBlock.requestFullscreen();
|
|
223
|
-
} else if (
|
|
222
|
+
} else if (document.querySelector('video').webkitRequestFullscreen) {
|
|
224
223
|
vpVideoBlock = document.querySelector('video');
|
|
225
224
|
await vpVideoBlock.webkitRequestFullscreen(); // Safari
|
|
226
225
|
} else if (vpVideoBlock.mozRequestFullScreen) {
|
|
@@ -228,7 +227,6 @@ async function startFullscreen() {
|
|
|
228
227
|
} else if (vpVideoBlock.msRequestFullscreen) {
|
|
229
228
|
await vpVideoBlock.msRequestFullscreen(); // IE/Edge
|
|
230
229
|
}
|
|
231
|
-
|
|
232
230
|
if (screen.orientation && screen.orientation.lock) {
|
|
233
231
|
try {
|
|
234
232
|
await screen.orientation.lock("landscape");
|
|
@@ -242,6 +240,7 @@ async function startFullscreen() {
|
|
|
242
240
|
console.error("Fullscreen could not be activated", error);
|
|
243
241
|
isFullscreen.value = false;
|
|
244
242
|
}
|
|
243
|
+
|
|
245
244
|
video.value.currentTime = currentTime;
|
|
246
245
|
}
|
|
247
246
|
}
|
|
@@ -252,7 +251,6 @@ function onSubtitleError(link) {
|
|
|
252
251
|
|
|
253
252
|
function onFullscreenChange(e) {
|
|
254
253
|
e.preventDefault();
|
|
255
|
-
|
|
256
254
|
// hide intro title after x seconds
|
|
257
255
|
if(isFullscreen.value === true) {
|
|
258
256
|
setTimeout(() => {
|
|
@@ -279,7 +277,7 @@ function onOrientationChange(e) {
|
|
|
279
277
|
let isPortrait = angle === 0 || angle === 180;
|
|
280
278
|
let isLandscape = angle === 90 || angle === -90;
|
|
281
279
|
|
|
282
|
-
if (
|
|
280
|
+
if (document.fullscreenElement && isPortrait) {
|
|
283
281
|
setTimeout(async () => {
|
|
284
282
|
if (!document.fullscreenElement) {
|
|
285
283
|
startFullscreen();
|
|
@@ -312,26 +310,15 @@ function seekVideo(time) {
|
|
|
312
310
|
function prepareVideoPlayer(link) {
|
|
313
311
|
let initiallyLoaded = true;
|
|
314
312
|
if (video.value) {
|
|
315
|
-
console.log("start hls gtest2 ", hls)
|
|
316
|
-
// video.value.src = link;
|
|
317
|
-
// video.value.load()
|
|
318
|
-
|
|
319
313
|
if (hls) {
|
|
314
|
+
hls.detachMedia();
|
|
320
315
|
hls.destroy();
|
|
321
316
|
initiallyLoaded = false;
|
|
322
317
|
}
|
|
323
|
-
console.log("a")
|
|
324
318
|
hls = new Hls();
|
|
325
|
-
console.log("b")
|
|
326
319
|
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)
|
|
320
|
+
hls.attachMedia(video.value)
|
|
321
|
+
hls.recoverMediaError()
|
|
335
322
|
|
|
336
323
|
video.value.muted = props.isMuted
|
|
337
324
|
video.value.currentTime = props.progress
|
|
@@ -373,10 +360,8 @@ console.log("attach to ", video.value)
|
|
|
373
360
|
}
|
|
374
361
|
});
|
|
375
362
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
initVideo();
|
|
379
|
-
// }
|
|
363
|
+
setInterval(checkTrackModeChanges, 100);
|
|
364
|
+
initVideo();
|
|
380
365
|
}
|
|
381
366
|
}
|
|
382
367
|
|
|
@@ -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++) {
|