Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/controller/eme-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class EMEController implements ComponentAPI {
private mediaKeysPromise: Promise<MediaKeys> | null = null;
private _onMediaEncrypted = this.onMediaEncrypted.bind(this);

// try to call setMediaKeys again after media attached if needed
private _attemptSetMediaKeysAgain: boolean = false;

/**
* @constructs
* @param {Hls} hls Our Hls.js instance
Expand Down Expand Up @@ -254,6 +257,7 @@ class EMEController implements ComponentAPI {
logger.log(`Media-keys created for key-system "${keySystem}"`);

this._onMediaKeysCreated();
this._attemptSetMediaKeys(mediaKeys);

return mediaKeys;
});
Expand Down Expand Up @@ -358,9 +362,11 @@ class EMEController implements ComponentAPI {
*/
private _attemptSetMediaKeys(mediaKeys?: MediaKeys) {
if (!this._media) {
throw new Error(
logger.warn(
'Attempted to set mediaKeys without first attaching a media element'
);
this._attemptSetMediaKeysAgain = true;
return;
}

if (!this._hasSetMediaKeys) {
Expand Down Expand Up @@ -653,6 +659,11 @@ class EMEController implements ComponentAPI {
// keep reference of media
this._media = media;

if (this._attemptSetMediaKeysAgain) {
// mediaKeys not set, attempt again
this._attemptSetMediaKeys();
}

media.addEventListener('encrypted', this._onMediaEncrypted);
}

Expand Down