@@ -383,7 +383,13 @@ function ProtectionController(config) {
383383 } else {
384384 log ( 'DRM: KeySystem Access Granted' ) ;
385385 eventBus . trigger ( events . KEY_SYSTEM_SELECTED , { data : event . data } ) ;
386- createKeySession ( supportedKS [ ksIdx ] . initData , supportedKS [ ksIdx ] . cdmData ) ;
386+ if ( supportedKS [ ksIdx ] . sessionId ) {
387+ // Load MediaKeySession with sessionId
388+ loadKeySession ( supportedKS [ ksIdx ] . sessionId , supportedKS [ ksIdx ] . initData ) ;
389+ } else if ( supportedKS [ ksIdx ] . initData ) {
390+ // Create new MediaKeySession with initData
391+ createKeySession ( supportedKS [ ksIdx ] . initData , supportedKS [ ksIdx ] . cdmData ) ;
392+ }
387393 }
388394 } ;
389395 eventBus . on ( events . KEY_SYSTEM_ACCESS_COMPLETE , onKeySystemAccessComplete , self ) ;
@@ -435,7 +441,13 @@ function ProtectionController(config) {
435441 const initData = { kids : Object . keys ( protData . clearkeys ) } ;
436442 pendingNeedKeyData [ i ] [ ksIdx ] . initData = new TextEncoder ( ) . encode ( JSON . stringify ( initData ) ) ;
437443 }
438- createKeySession ( pendingNeedKeyData [ i ] [ ksIdx ] . initData , pendingNeedKeyData [ i ] [ ksIdx ] . cdmData ) ;
444+ if ( pendingNeedKeyData [ i ] [ ksIdx ] . sessionId ) {
445+ // Load MediaKeySession with sessionId
446+ loadKeySession ( pendingNeedKeyData [ i ] [ ksIdx ] . sessionId , pendingNeedKeyData [ i ] [ ksIdx ] . initData ) ;
447+ } else if ( pendingNeedKeyData [ i ] [ ksIdx ] . initData !== null ) {
448+ // Create new MediaKeySession with initData
449+ createKeySession ( pendingNeedKeyData [ i ] [ ksIdx ] . initData , pendingNeedKeyData [ i ] [ ksIdx ] . cdmData ) ;
450+ }
439451 break ;
440452 }
441453 }
0 commit comments