@grfzhl/vue-hls-player 1.0.18 → 1.0.20

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.
@@ -46,6 +46,7 @@
46
46
  :src="subtitle.link"
47
47
  kind="subtitles"
48
48
  :srclang="subtitle.lang"
49
+ @error="onSubtitleError(subtitle.link)"
49
50
  :label="subtitle.label" :default="i === 0" />
50
51
  </video>
51
52
  </media-theme-sutro>
@@ -68,7 +69,7 @@
68
69
  </template>
69
70
 
70
71
  <script setup>
71
- import { onMounted, onUpdated, ref, onUnmounted, computed, watch } from 'vue'
72
+ import { onMounted, onUpdated, ref, onUnmounted, computed, watch, toRef } from 'vue'
72
73
  import Hls from 'hls.js'
73
74
  import 'player.style/sutro';
74
75
  import SubtitleBlock from './SubtitleBlock.vue';
@@ -139,6 +140,9 @@ const orientation = ref(null)
139
140
  const autoHideIntroTitle = ref(false);
140
141
  const initialPlayButton = ref(false);
141
142
  const hideInitialPlayButton = ref(false)
143
+ const link = toRef(props, 'link');
144
+ const previewImageLink = toRef(props, 'previewImageLink');
145
+ let hls = new Hls()
142
146
 
143
147
  const videoElement = defineModel()
144
148
 
@@ -216,10 +220,10 @@ onUpdated(() => {
216
220
  onUnmounted(() => {
217
221
  if (video.value) {
218
222
  video.value.removeEventListener('timeupdate', updateCurrentTime);
219
- document.removeEventListener('fullscreenchange', onFullscreenChange);
220
- document.removeEventListener('orientationchange', onOrientationChange);
221
- window.screen.orientation.addEventListener("change", onOrientationChange);
222
223
  }
224
+ document.removeEventListener('fullscreenchange', onFullscreenChange);
225
+ document.removeEventListener('orientationchange', onOrientationChange);
226
+ window.screen.orientation.removeEventListener("change", onOrientationChange);
223
227
  });
224
228
 
225
229
  const mutedAttr = computed(() => {
@@ -238,15 +242,23 @@ const currentSubtitle = computed(() => {
238
242
  })
239
243
 
240
244
  watch([props, videoElement], (a) => {
241
- if(a[0].autoplay && a[1]) {
245
+ if(a[0].autoplay && a[1] && a[1].paused) {
242
246
  // autoplay is only possible when muted
243
247
  a[1].muted = true
244
248
  setTimeout(() => {
245
- a[1].play();
249
+ a[1].play().catch(err => console.warn("Autoplay-Error:", err));
246
250
  }, 200)
247
251
  }
248
252
  })
249
253
 
254
+ watch(link, (v) => {
255
+ prepareVideoPlayer();
256
+ })
257
+
258
+ function onSubtitleError(link) {
259
+ console.error(`Error on loading subtitles: ${link}`);
260
+ }
261
+
250
262
  function onFullscreenChange() {
251
263
  isFullscreen.value = !!document.fullscreenElement
252
264
  emit('video-fullscreen-change', document.fullscreenElement)
@@ -295,9 +307,9 @@ function seekVideo(time) {
295
307
  }
296
308
 
297
309
  function prepareVideoPlayer() {
298
- let hls = new Hls()
299
310
  let stream = props.link
300
311
  hls.loadSource(stream)
312
+ hls.attachMedia(video.value)
301
313
 
302
314
  if (video.value) {
303
315
  hls.attachMedia(video.value)
@@ -26,13 +26,13 @@
26
26
 
27
27
  <script setup>
28
28
  import BasePlayer from './BasePlayer.vue'
29
- import { ref } from 'vue'
29
+ import { ref, toRef } from 'vue'
30
30
 
31
31
  const emit = defineEmits(['pause', 'video-ended', 'video-fullscreen-change', 'video-fullscreen-action'])
32
32
 
33
33
  const videoElement = ref(null);
34
34
 
35
- defineProps({
35
+ const props = defineProps({
36
36
  previewImageLink: {
37
37
  type: String,
38
38
  default: ''
@@ -75,6 +75,9 @@ defineProps({
75
75
  }
76
76
  })
77
77
 
78
+ const link = toRef(props, 'link');
79
+ const previewImageLink = toRef(props, 'previewImageLink');
80
+
78
81
  function pause(currentTime) {
79
82
  emit('pause', currentTime)
80
83
  }
@@ -32,13 +32,13 @@
32
32
  <script setup>
33
33
  import VDefaultVideoPlayer from './VDefaultVideoPlayer.vue'
34
34
  import VPreviewVideoPlayer from './VPreviewVideoPlayer.vue'
35
- import { ref } from 'vue'
35
+ import { ref, toRef } from 'vue'
36
36
 
37
37
  const emit = defineEmits(['pause', 'video-ended', 'video-fullscreen-change', 'video-fullscreen-action'])
38
38
 
39
39
  const videoElement = ref(null);
40
40
 
41
- defineProps({
41
+ const props = defineProps({
42
42
  previewImageLink: {
43
43
  type: String,
44
44
  default: ''
@@ -85,6 +85,9 @@ defineProps({
85
85
  }
86
86
  })
87
87
 
88
+ const link = toRef(props, 'link');
89
+ const previewImageLink = toRef(props, 'previewImageLink');
90
+
88
91
  function pause(currentTime) {
89
92
  emit('pause', currentTime)
90
93
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@grfzhl/vue-hls-player",
3
3
  "private": false,
4
- "version": "1.0.18",
4
+ "version": "1.0.20",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"