diff --git a/src/loader/level-key.ts b/src/loader/level-key.ts index 49d4dd925f7..f84f70473b8 100644 --- a/src/loader/level-key.ts +++ b/src/loader/level-key.ts @@ -3,7 +3,7 @@ import { hexToArrayBuffer } from '../utils/hex'; import { convertDataUriToArrayBytes } from '../utils/keysystem-util'; import { logger } from '../utils/logger'; import { KeySystemFormats, parsePlayReadyWRM } from '../utils/mediakeys-helper'; -import { mp4pssh } from '../utils/mp4-tools'; +import { mp4pssh, parseMultiPssh } from '../utils/mp4-tools'; let keyUriToKeyIdMap: { [uri: string]: Uint8Array } = {}; @@ -142,7 +142,14 @@ export class LevelKey implements DecryptData { // the playlist-key before the "encrypted" event. (Comment out to only use "encrypted" path.) this.pssh = keyBytes; // In case of Widevine, if KEYID is not in the playlist, assume only two fields in the pssh KEY tag URI. - if (!this.keyId && keyBytes.length >= 22) { + if (!this.keyId) { + const [psshData] = parseMultiPssh(keyBytes.buffer); + this.keyId = + psshData && 'kids' in psshData && psshData.kids?.[0] + ? psshData.kids[0] + : null; + } + if (!this.keyId) { const offset = keyBytes.length - 22; this.keyId = keyBytes.subarray(offset, offset + 16); }