|
2 | 2 | @model PageSectionDetailViewModel |
3 | 3 | @{ |
4 | 4 | string mkPlayerLicence = (string)ViewData["mkPlayerLicenceKey"]; |
5 | | - var scheme = Context?.Request?.Scheme ?? "undefined"; |
6 | | - var host = Context?.Request?.Host; |
7 | | - var path = Context?.Request?.Path ?? "undefined"; |
8 | | - var requestURL = $"{scheme}://{host}{path}"; |
9 | 5 | } |
10 | 6 |
|
| 7 | +@* <link href="~/css/mkplayer-ui.css" rel="stylesheet" asp-append-version="true" /> *@ |
11 | 8 | <script type="text/javascript" src="~/js/mkplayer.js" asp-append-version="true"></script> |
12 | 9 |
|
13 | 10 | @* @if (Model != null) |
|
53 | 50 | } *@ |
54 | 51 | <div class="video-container" id="@($"{"videoContainer"}{Model.Id}")"></div> |
55 | 52 |
|
56 | | -<script type="text/javascript"> |
| 53 | +<script> |
57 | 54 |
|
58 | 55 | var model = @Json.Serialize(Model); |
59 | 56 | // 1. Grab the video container |
|
62 | 59 | // 2. Prepare the player configuration |
63 | 60 | var playerConfig = { |
64 | 61 | key: "@mkPlayerLicence", |
65 | | - ui: true, |
| 62 | + ui: false, |
66 | 63 | theme: "dark", |
67 | 64 | playback: { |
68 | 65 | muted: false, |
69 | 66 | autoplay: false, |
70 | 67 | preferredTech: [{ player: 'html5', streaming: 'hls' }] |
71 | | - } |
| 68 | + }, |
| 69 | +
|
| 70 | + // Subscribe to player events |
| 71 | + events: { |
| 72 | + [mkplayer.MKPlayerEvent.Error]: (event) => { |
| 73 | + console.log("Encountered player error: ", JSON.stringify(event)); |
| 74 | + }, |
| 75 | + [mkplayer.MKPlayerEvent.TimeChanged]: (event) => { |
| 76 | + console.log("Current player position: ", event.time); |
| 77 | + }, |
| 78 | + [mkplayer.MKPlayerEvent.Muted]: (data) => { |
| 79 | + console.log("Audio muted!") |
| 80 | + }, |
| 81 | + [mkplayer.MKPlayerEvent.Unmuted]: onUnmute, |
| 82 | +
|
| 83 | + [mkplayer.MKPlayerEvent.Ready]: () => { |
| 84 | +
|
| 85 | + // debugger; |
| 86 | + //var caption = model.videoAsset.closedCaptionsFile.fileName; |
| 87 | +
|
| 88 | + // var subtitleTrack = { |
| 89 | + // id: "@($"{"subid"}{Model.Id}")", |
| 90 | + // lang: "en", |
| 91 | + // label: "Custom Subtitle", |
| 92 | + // url: "https://bitdash-a.akamaihd.net/content/sintel/subtitles/subtitles_en.vtt", |
| 93 | + // kind: "subtitle" |
| 94 | + // }; |
| 95 | + // player.addSubtitle(subtitleTrack); |
| 96 | + }, |
| 97 | + [mkplayer.MKPlayerEvent.SubtitleAdded]: () => { |
| 98 | + // player.enableSubtitle("@($"{"subid"}{Model.Id}")"); |
| 99 | + }, |
| 100 | + [mkplayer.MKPlayerEvent.playbackSpeed]: (data) => { |
| 101 | + alert("Video playback quality changed to: "); |
| 102 | + }, |
| 103 | + } |
72 | 104 | }; |
73 | 105 |
|
74 | 106 | // 3. Initialize the player with video container and player configuration |
75 | 107 | var player = new mkplayer.MKPlayer(videoContainer, playerConfig); |
76 | 108 |
|
77 | | - // [BY] Commenting and leaving this code here for future reference : When we set UI:false, we need to manually add controls |
78 | | - // ----------------------------------------------------------------------------------------------------------------------- |
79 | | - // player.on(mkplayer.MKPlayerEvent.Ready, (event) => { |
80 | | - // const videoElement = document.getElementById("@($"{"bitmovinplayer-video-videoContainer"}{Model.Id}")"); |
81 | | - // if (videoElement) { |
82 | | - // videoElement.controls = true; |
83 | | -
|
84 | | - // // Check if captions available |
85 | | - // if (model.videoAsset.closedCaptionsFile) { |
86 | | - // const captionsInfo = model.videoAsset.closedCaptionsFile; |
87 | | - // if (captionsInfo.filePath) { |
88 | | - // const trackElement = document.createElement('track'); |
89 | | - // const srcPath = "/file/download/" + captionsInfo.filePath + "/" + captionsInfo.fileName; |
90 | | - // trackElement.kind = 'captions'; // Or 'subtitles' or 'descriptions' depending on your track type |
91 | | - // trackElement.label = captionsInfo.language || 'english'; |
92 | | - // trackElement.srclang = captionsInfo.language || 'en'; |
93 | | - // trackElement.src = srcPath; |
94 | | -
|
95 | | - // // Append the track to the video element |
96 | | - // videoElement.appendChild(trackElement); |
97 | | - // } |
98 | | - // } |
99 | | - // } |
100 | | - // }); |
101 | | - // ----------------------------------------------------------------------------------------------------------------------- |
| 109 | + player.on("loaded", () => { |
| 110 | + playerElement.addEventListener("mousemove", () => { |
| 111 | + }); |
| 112 | + }); |
| 113 | +
|
| 114 | + player.on(mkplayer.MKPlayerEvent.SourceLoaded, (event) => { |
| 115 | + console.log("Source loaded successfully!"); |
| 116 | + }); |
| 117 | +
|
| 118 | + player.on(mkplayer.MKPlayerEvent.Ready, (event) => { |
| 119 | +
|
| 120 | + const videoElement = document.getElementById("@($"{"bitmovinplayer-video-videoContainer"}{Model.Id}")"); |
| 121 | + if (videoElement) { |
| 122 | + videoElement.controls = true; |
| 123 | + // debugger; |
| 124 | + // Check if captions available |
| 125 | + if (model.videoAsset.closedCaptionsFile) { |
| 126 | + const captionsInfo = model.videoAsset.closedCaptionsFile; |
| 127 | + if (captionsInfo.filePath) { |
| 128 | + const trackElement = document.createElement('track'); |
| 129 | + // const srcPath = "/file/download?filePath=" + captionsInfo.filePath + "&fileName=" + captionsInfo.fileName; |
| 130 | + const srcPath = "/file/download/" + captionsInfo.filePath + "/" + captionsInfo.fileName; |
| 131 | + trackElement.kind = 'captions'; // Or 'subtitles' or 'descriptions' depending on your track type |
| 132 | + trackElement.label = captionsInfo.language || 'english'; |
| 133 | + trackElement.srclang = captionsInfo.language || 'en'; |
| 134 | + // trackElement.src = "/api/resource/DownloadResource?filePath=396eb836-5cf5-4255-b33f-66a31fdbef39&fileName=samplecaption.vtt"; |
| 135 | + // trackElement.src = "https://bitdash-a.akamaihd.net/content/sintel/subtitles/subtitles_en.vtt"; |
| 136 | + trackElement.src = srcPath; |
| 137 | +
|
| 138 | +
|
| 139 | + // Append the track to the video element |
| 140 | + videoElement.appendChild(trackElement); |
| 141 | +
|
| 142 | + // Add event listener to TextTrackList for when a new text track is added |
| 143 | + // videoElement.textTracks.addEventListener('addtrack', function (event) { |
| 144 | + // let track = event.track; |
| 145 | + // console.log('Track added:', track); |
| 146 | +
|
| 147 | + // if (track.kind === 'subtitles' || track.kind === 'captions') { |
| 148 | + // track.mode = 'showing'; // Automatically show captions |
| 149 | + // console.log('Track showing:', track); |
| 150 | + // } |
| 151 | + // }); |
| 152 | +
|
| 153 | + // trackElement.addEventListener('load', function () { |
| 154 | + // debugger; |
| 155 | + // this.track.mode = 'showing'; // Automatically show captions |
| 156 | + // alert('Track loaded and showing:', this.track); |
| 157 | + // }); |
| 158 | +
|
| 159 | + // Manually check and set track mode after a slight delay |
| 160 | + // setTimeout(() => { |
| 161 | + // var textTracks = videoElement.textTracks; |
| 162 | + // for (let i = 0; i < textTracks.length; i++) { |
| 163 | + // if ((textTracks[i].kind === 'subtitles' || textTracks[i].kind === 'captions') && textTracks[i].src === srcPath) { |
| 164 | + // textTracks[i].mode = 'showing'; |
| 165 | + // debugger; |
| 166 | + // console.log('Track set to showing:', textTracks[i]); |
| 167 | + // } |
| 168 | + // } |
| 169 | + // }, 1000); |
| 170 | +
|
| 171 | + // Ensure the track is loaded and ready |
| 172 | + // trackElement.addEventListener('load', function () { |
| 173 | + // debugger; |
| 174 | + // this.mode = 'showing'; // Automatically show captions |
| 175 | + // }); |
| 176 | +
|
| 177 | + } |
| 178 | + } |
| 179 | + } |
| 180 | +
|
| 181 | + // document.getElementById("@($"{"bitmovinplayer-video-videoContainer"}{Model.Id}")").controls = true; |
| 182 | + // console.log("Player is ready for playback!"); |
| 183 | + }); |
102 | 184 |
|
103 | 185 | var url = model.videoAsset.azureMediaAsset.locatorUri; |
104 | 186 | url = url.substring(0, url.lastIndexOf("manifest")) + "manifest(format=m3u8-cmaf,encryption=cbc)"; |
105 | 187 |
|
106 | | - var subtitleTrack = null; |
107 | | - if (model.videoAsset.closedCaptionsFile) { |
108 | | - const captionsInfo = model.videoAsset.closedCaptionsFile; |
109 | | - var srcPath = "file/download/" + captionsInfo.filePath + "/" + captionsInfo.fileName; |
110 | | - srcPath = '@requestURL' + srcPath; |
111 | | - |
112 | | - subtitleTrack = { |
113 | | - id: "subtitle", |
114 | | - lang: "en", |
115 | | - label: "english", |
116 | | - url: srcPath, |
117 | | - kind: "subtitle" |
118 | | - }; |
119 | | - } |
120 | | -
|
121 | 188 | var sourceConfig = { |
122 | 189 | hls: url, |
123 | | - subtitleTracks: [subtitleTrack], |
| 190 | + // Custom subtitle track |
| 191 | + // subtitleTracks: [{ |
| 192 | + // id: "sub1", |
| 193 | + // lang: "en", |
| 194 | + // label: "Custom Subtitle", |
| 195 | + // url: "https://bitdash-a.akamaihd.net/content/sintel/subtitles/subtitles_en.vtt", |
| 196 | + // kind: "subtitle" |
| 197 | + // }], |
124 | 198 | drm: { |
125 | 199 | clearkey: { |
126 | 200 | LA_URL: "HLS_AES", |
|
133 | 207 |
|
134 | 208 | player.load(sourceConfig) |
135 | 209 | .then(() => { |
| 210 | + // you can also get notified when subscribed to `SourceLoaded` event. |
136 | 211 | console.log("Source loaded successfull!"); |
137 | 212 | }) |
138 | 213 | .catch((error) => { |
139 | 214 | console.error("An error occurred while loading the source!"); |
140 | 215 | }); |
| 216 | +
|
| 217 | + function onUnmute(data) { |
| 218 | + console.log("Audio unmuted!"); |
| 219 | + } |
141 | 220 | </script> |
142 | 221 |
|
143 | 222 | <style> |
|
0 commit comments