@grfzhl/vue-hls-player 1.0.3 → 1.0.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.
package/README.md CHANGED
@@ -120,6 +120,11 @@ it can show and hide the video control panel
120
120
  subtitles to add as tracks to the video
121
121
 
122
122
  ### Last release:
123
+ v1.0.4
124
+ 1. Make subtitles dynamic
125
+ 2. Add new switch to disable the subtitle block
126
+ 3. Fix some minor issues
127
+
123
128
  v1.0.3
124
129
  1. Removed controls in favour of themable overlay by `player.style`.
125
130
  2. Updated hls library
@@ -29,11 +29,11 @@
29
29
  </media-theme-sutro>
30
30
  <div ref="subtitlesContainer" class="custom-subtitles"></div>
31
31
  </div>
32
- <SubtitleBlock :vttFile="subtitles[0]" :cursor="videoCursor"></SubtitleBlock>
32
+ <SubtitleBlock v-if="showSubtitleBlock" :subtitle="currentSubtitle" :cursor="videoCursor"></SubtitleBlock>
33
33
  </template>
34
34
 
35
35
  <script setup>
36
- import { onMounted, onUpdated, ref, onUnmounted } from 'vue'
36
+ import { onMounted, onUpdated, ref, onUnmounted, computed } from 'vue'
37
37
  import Hls from 'hls.js'
38
38
  import 'player.style/sutro';
39
39
  import SubtitleBlock from './SubtitleBlock.vue';
@@ -67,12 +67,21 @@ const props = defineProps({
67
67
  subtitles: {
68
68
  type: Array,
69
69
  default: []
70
+ },
71
+ /**
72
+ * true, if showing separate
73
+ * block with transcripts
74
+ */
75
+ showSubtitleBlock: {
76
+ type: Boolean,
77
+ default: true
70
78
  }
71
79
  })
72
80
 
73
81
  const emit = defineEmits(['pause', 'test'])
74
82
  const video = ref(null)
75
83
  const subtitlesContainer = ref(null)
84
+ const currentSubtitleLang = ref(null)
76
85
  const videoCursor = ref(0)
77
86
 
78
87
  onMounted(() => {
@@ -91,6 +100,17 @@ onUnmounted(() => {
91
100
  }
92
101
  });
93
102
 
103
+ const currentSubtitle = computed(() => {
104
+ if(props.subtitles) {
105
+ const current = props.subtitles.filter((subt) => {
106
+ return subt.lang === currentSubtitleLang.value
107
+ })
108
+ console.log("found current", current)
109
+ return current.length ? current[0] : null
110
+ }
111
+ return null
112
+ })
113
+
94
114
  function updateCurrentTime() {
95
115
  videoCursor.value = video.value.currentTime;
96
116
  }
@@ -111,6 +131,7 @@ function prepareVideoPlayer() {
111
131
  Array.from(textTracks).forEach((track, index) => {
112
132
  track.addEventListener("cuechange", () => {
113
133
  const activeCues = track.activeCues;
134
+ currentSubtitleLang.value = track.language
114
135
  if (activeCues && activeCues.length > 0) {
115
136
  subtitlesContainer.value.textContent = activeCues[0].text
116
137
  subtitlesContainer.value.style.display = "block";
@@ -119,9 +140,9 @@ function prepareVideoPlayer() {
119
140
  }
120
141
  });
121
142
  if (track.mode !== previousModes[index]) {
122
- console.log(`Track mode changed: ${track.mode}`);
123
143
  if (track.mode === "showing") {
124
144
  const activeCues = track.activeCues;
145
+ currentSubtitleLang.value = track.language
125
146
  if (activeCues && activeCues.length > 0) {
126
147
  subtitlesContainer.value.style.display = "block";
127
148
  subtitlesContainer.value.textContent = activeCues[0].text
@@ -20,9 +20,9 @@
20
20
  import { onMounted, onUpdated, ref } from 'vue'
21
21
 
22
22
  const props = defineProps({
23
- vttFile: {
24
- type: String,
25
- default: ''
23
+ subtitle: {
24
+ type: Object,
25
+ default: null
26
26
  },
27
27
  cursor: {
28
28
  type: Number,
@@ -35,11 +35,15 @@ const subtitlesContainer = ref(null)
35
35
  const cues = ref([])
36
36
 
37
37
  onMounted(async () => {
38
- cues.value = await parseVTT(props.vttFile.link)
39
- console.log(cues.value)
38
+ if(props.subtitle) {
39
+ cues.value = await parseVTT(props.subtitle.link)
40
+ }
40
41
  })
41
42
 
42
43
  onUpdated(async () => {
44
+ if(props.subtitle) {
45
+ cues.value = await parseVTT(props.subtitle.link)
46
+ }
43
47
  // auto scroll text
44
48
  if(subtitlesContainer) {
45
49
  const activeSubtitle = subtitlesContainer?.value?.querySelectorAll('li.current-highlight')[0];
@@ -6,7 +6,6 @@
6
6
  :link="link"
7
7
  :progress="progress"
8
8
  :isMuted="isMuted"
9
- :isControls="isControls"
10
9
  />
11
10
 
12
11
  <VPreviewVideoPlayer
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.3",
4
+ "version": "1.0.4",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"