Skip to content

Commit

Permalink
Merge branch 'com-1118-poc-implementation-focus-on-web-and-live-strea…
Browse files Browse the repository at this point in the history
…ming' of github.com:Uscreen-video/video-player into next
  • Loading branch information
sck-v committed Oct 3, 2024
2 parents 7a1ca51 + 934f029 commit 616e009
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
44 changes: 29 additions & 15 deletions src/components/video-container/Video-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,19 @@ export class VideoContainer extends LitElement {

@listen(Types.Command.init, { isSourceSupported: true })
initNative() {
this.sources.enableSource();
if (this.muxData)
if (this.muxData) {
connectMuxData(this.videos[0], {
...this.muxData,
player_init_time: this.initTime,
});
}

if (this.drmOptions && this.drmOptions[KeySystems.fps]) {
if (this.drmOptions?.[KeySystems.fps]) {
initFairPlayDRM(this.videos[0], this.drmOptions[KeySystems.fps]);
}

// Init source after the video events are set
this.sources.enableSource();
}

@listen(Types.Command.initCustomHLS)
Expand All @@ -267,18 +270,21 @@ export class VideoContainer extends LitElement {
backBufferLength: navigator.userAgent.match(/Android/i) ? 0 : 30,
liveDurationInfinity: true,
emeEnabled: !!this.drmOptions,
drmSystems: this.drmOptions ? {
'com.apple.fps': {
licenseUrl: this.drmOptions[KeySystems.fps].licenseUrl,
serverCertificateUrl: this.drmOptions[KeySystems.fps].certificateUrl,
},
'com.widevine.alpha': {
licenseUrl: this.drmOptions[KeySystems.widevine].licenseUrl
},
'com.microsoft.playready': {
licenseUrl: this.drmOptions[KeySystems.playready].licenseUrl
}
} : {}
drmSystems: this.drmOptions
? {
"com.apple.fps": {
licenseUrl: this.drmOptions[KeySystems.fps]?.licenseUrl,
serverCertificateUrl:
this.drmOptions[KeySystems.fps]?.certificateUrl,
},
"com.widevine.alpha": {
licenseUrl: this.drmOptions[KeySystems.widevine]?.licenseUrl,
},
"com.microsoft.playready": {
licenseUrl: this.drmOptions[KeySystems.playready]?.licenseUrl,
},
}
: {},
});

if (this.muxData)
Expand Down Expand Up @@ -350,6 +356,7 @@ export class VideoContainer extends LitElement {
handleVideoEvent(e: Event & { target: HTMLVideoElement }) {
const type = e.type;
const video = this.videos[0];

switch (type) {
case "play":
dispatch(this, Types.Action.play);
Expand Down Expand Up @@ -401,6 +408,13 @@ export class VideoContainer extends LitElement {
break;
case "loadedmetadata":
dispatch(this, Types.Action.canPlay);
const duration = getVideoDuration(video);
if (duration && duration !== Infinity) {
dispatch(this, Types.Action.updateDuration, {
initialized: true,
duration,
});
}
break;
case "error":
if (!this.isSourceSupported) return;
Expand Down
11 changes: 2 additions & 9 deletions src/helpers/drm.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { DRMSystemConfiguration } from "../types";

export const initFairPlayDRM = async (
element: HTMLElement,
fairPlayOptions: DRMSystemConfiguration,
) => {
export const initFairPlayDRM = async (videoElement: HTMLVideoElement, fairPlayOptions: DRMSystemConfiguration) => {
const certificateUrl = fairPlayOptions.certificateUrl;
const licenseServerUrl = fairPlayOptions.licenseUrl;

const fairPlayCertificate = await loadFairPlayCertificate(certificateUrl);

element.addEventListener(
"encrypted",
fairplayEncryptedCallback(fairPlayCertificate, licenseServerUrl),
);
videoElement.addEventListener('encrypted', fairplayEncryptedCallback(fairPlayCertificate, licenseServerUrl));
};

const loadFairPlayCertificate = async (certificateUrl: string) => {
Expand All @@ -38,7 +32,6 @@ const fairplayEncryptedCallback = (fairPlayCertificate: ArrayBuffer, licenseServ
],
);

console.log(access);
let keys = await access.createMediaKeys();

await keys.setServerCertificate(fairPlayCertificate);
Expand Down

0 comments on commit 616e009

Please sign in to comment.