Skip to content

Commit ef34ffd

Browse files
authored
Merge pull request #1813 from TechnologyEnhancedLearning/Develop/Fixes/TD-7339-Videos-display-incorrectly-on-edit-view-for-multi‑page-resources-(videos-from-page-1-appear-on-all-pages)
TD-7339: Videos display incorrectly on edit view for multi‑page reso…
2 parents 40967e4 + e3844af commit ef34ffd

1 file changed

Lines changed: 49 additions & 24 deletions

File tree

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

Lines changed: 49 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() {
@@ -100,19 +104,15 @@
100104
this.playBackUrl = this.playBackUrl.substring(0, this.playBackUrl.lastIndexOf("manifest")) + "manifest(format=m3u8-cmaf,encryption=cbc)";
101105
if (this.isIphone) {
102106
this.playBackUrl = "/Media/MediaManifest?playBackUrl=" + this.playBackUrl + "&token=" + this.azureMediaServicesToken;
103-
}
107+
}
104108
},
105109
checkIfIphone() {
106110
const userAgent = navigator.userAgent || navigator.vendor;
107111
this.isIphone = /iPhone/i.test(userAgent);
108112
},
109113
load() {
110114
// Grab the video container
111-
this.videoContainer = document.getElementById(this.getPlayerUniqueId);
112-
113-
if (!this.mkioKey) {
114-
this.getMKIOPlayerKey();
115-
}
115+
this.videoContainer = document.getElementById(this.playerUniqueId);
116116
117117
// Prepare the player configuration
118118
const playerConfig = {
@@ -168,15 +168,16 @@
168168
}
169169
},
170170
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-
},
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+
// console.log("getPlayerUniqueId " + this.fileId);
179+
// return `videoContainer_${this.fileId}_${time}`
180+
//},
180181
captionsTrackAvailable(): boolean {
181182
return !!this.videoFile
182183
&& !!this.videoFile.captionsFile
@@ -200,6 +201,22 @@
200201
return this.transcriptFileModel.getDownloadResourceLink();
201202
},
202203
},
204+
watch: {
205+
videoFile: {
206+
immediate: true,
207+
handler() {
208+
if (this.player) {
209+
this.player.destroy();
210+
}
211+
212+
this.getMediaPlayUrl();
213+
214+
this.$nextTick(() => {
215+
this.load();
216+
});
217+
}
218+
}
219+
}
203220
})
204221
</script>
205222

@@ -232,41 +249,49 @@
232249
--min-width: 200px;
233250
}
234251
}
252+
235253
@media (min-width: 375px) { /* Non standard for graceful */
236254
.video-container {
237255
--min-width: 300px;
238256
}
239257
}
258+
240259
@media (min-width: 450px) { /* Non standard for graceful */
241260
.video-container {
242261
--min-width: 400px;
243262
}
244263
}
264+
245265
@media (min-width: 576px) {
246266
.video-container {
247267
--min-width: 500px;
248268
}
249269
}
270+
250271
@media (min-width: 650px) { /* Non standard for graceful */
251272
.video-container {
252273
--min-width: 600px;
253274
}
254275
}
276+
255277
@media (min-width: 768px) {
256278
.video-container {
257279
--min-width: 700px;
258280
}
259281
}
282+
260283
@media (min-width: 850px) { /* Non standard for graceful */
261284
.video-container {
262285
--min-width: 800px;
263286
}
264287
}
265-
@media (min-width: 992px) {
288+
289+
@media (min-width: 992px) {
266290
.video-container {
267291
--min-width: 900px;
268292
}
269-
}
293+
}
294+
270295
@media (min-width: 1024px) {
271296
.video-container {
272297
--min-width: 1024px;

0 commit comments

Comments
 (0)