Skip to content

Commit 9b918ff

Browse files
TD-7339: Videos display incorrectly on edit view for multi‑page resources (videos from page 1 appear on all pages)
1 parent fdb86fd commit 9b918ff

1 file changed

Lines changed: 50 additions & 24 deletions

File tree

LearningHub.Nhs.WebUI/Scripts/vuesrc/contribute-resource/components/MKIOVideoPlayer.vue

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<link href="~/css/mkplayer-ui.css" rel="stylesheet" asp-append-version="true" />
22
<template>
33
<div>
4-
<div :id="getPlayerUniqueId" class="video-container"></div>
4+
<div :id="playerUniqueId" class="video-container"></div>
55
<noscript>
66
<p class="amp-no-js">
77
To view this media please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video
@@ -50,16 +50,20 @@
5050
mkioKey: '',
5151
playBackUrl: '',
5252
sourceLoaded: true,
53-
isIphone: false
53+
isIphone: false,
54+
playerUniqueId: `videoContainer_${this.fileId}_${Date.now()}` // We need to generate a new unique ID for the video player on every render otherwise the video player will not load properly.
5455
};
5556
},
56-
async created() {
57+
async mounted() {
58+
this.checkIfIphone();
59+
5760
await this.getMKIOPlayerKey();
61+
5862
this.getMediaPlayUrl();
59-
this.load();
60-
},
61-
mounted() {
62-
this.checkIfIphone();
63+
64+
this.$nextTick(() => {
65+
this.load();
66+
});
6367
},
6468
methods: {
6569
onPlayerReady() {
@@ -96,23 +100,20 @@
96100
return "Bearer=" + this.azureMediaServicesToken;
97101
},
98102
getMediaPlayUrl() {
103+
console.log(this.videoFile.locatorUri);
99104
this.playBackUrl = this.videoFile.locatorUri;
100105
this.playBackUrl = this.playBackUrl.substring(0, this.playBackUrl.lastIndexOf("manifest")) + "manifest(format=m3u8-cmaf,encryption=cbc)";
101106
if (this.isIphone) {
102107
this.playBackUrl = "/Media/MediaManifest?playBackUrl=" + this.playBackUrl + "&token=" + this.azureMediaServicesToken;
103-
}
108+
}
104109
},
105110
checkIfIphone() {
106111
const userAgent = navigator.userAgent || navigator.vendor;
107112
this.isIphone = /iPhone/i.test(userAgent);
108113
},
109114
load() {
110115
// Grab the video container
111-
this.videoContainer = document.getElementById(this.getPlayerUniqueId);
112-
113-
if (!this.mkioKey) {
114-
this.getMKIOPlayerKey();
115-
}
116+
this.videoContainer = document.getElementById(this.playerUniqueId);
116117
117118
// Prepare the player configuration
118119
const playerConfig = {
@@ -168,15 +169,16 @@
168169
}
169170
},
170171
computed: {
171-
getPlayerUniqueId(): string {
172-
// We need to generate a new unique ID for the video player on every render otherwise the video player will not load properly.
173-
// This is because the AMP is only intended to be a static player and so is not optimised for componentisation.
174-
// So, when we switch between tabs on the Case resource creation page, the video player unmounts and then remounts if
175-
// we go back to the Contents tab. As a result, a new unique ID is needed so that the media player knows it has to
176-
// initalise itself again, which we do in the `mounted()` lifecycle method above.
177-
const time = new Date().getTime()
178-
return `videoContainer_${this.fileId}_${time}`
179-
},
172+
//getPlayerUniqueId(): string {
173+
// // We need to generate a new unique ID for the video player on every render otherwise the video player will not load properly.
174+
// // This is because the AMP is only intended to be a static player and so is not optimised for componentisation.
175+
// // So, when we switch between tabs on the Case resource creation page, the video player unmounts and then remounts if
176+
// // we go back to the Contents tab. As a result, a new unique ID is needed so that the media player knows it has to
177+
// // initalise itself again, which we do in the `mounted()` lifecycle method above.
178+
// const time = new Date().getTime()
179+
// console.log("getPlayerUniqueId " + this.fileId);
180+
// return `videoContainer_${this.fileId}_${time}`
181+
//},
180182
captionsTrackAvailable(): boolean {
181183
return !!this.videoFile
182184
&& !!this.videoFile.captionsFile
@@ -200,6 +202,22 @@
200202
return this.transcriptFileModel.getDownloadResourceLink();
201203
},
202204
},
205+
watch: {
206+
videoFile: {
207+
immediate: true,
208+
handler() {
209+
if (this.player) {
210+
this.player.destroy();
211+
}
212+
213+
this.getMediaPlayUrl();
214+
215+
this.$nextTick(() => {
216+
this.load();
217+
});
218+
}
219+
}
220+
}
203221
})
204222
</script>
205223

@@ -232,41 +250,49 @@
232250
--min-width: 200px;
233251
}
234252
}
253+
235254
@media (min-width: 375px) { /* Non standard for graceful */
236255
.video-container {
237256
--min-width: 300px;
238257
}
239258
}
259+
240260
@media (min-width: 450px) { /* Non standard for graceful */
241261
.video-container {
242262
--min-width: 400px;
243263
}
244264
}
265+
245266
@media (min-width: 576px) {
246267
.video-container {
247268
--min-width: 500px;
248269
}
249270
}
271+
250272
@media (min-width: 650px) { /* Non standard for graceful */
251273
.video-container {
252274
--min-width: 600px;
253275
}
254276
}
277+
255278
@media (min-width: 768px) {
256279
.video-container {
257280
--min-width: 700px;
258281
}
259282
}
283+
260284
@media (min-width: 850px) { /* Non standard for graceful */
261285
.video-container {
262286
--min-width: 800px;
263287
}
264288
}
265-
@media (min-width: 992px) {
289+
290+
@media (min-width: 992px) {
266291
.video-container {
267292
--min-width: 900px;
268293
}
269-
}
294+
}
295+
270296
@media (min-width: 1024px) {
271297
.video-container {
272298
--min-width: 1024px;

0 commit comments

Comments
 (0)