@ -1004,6 +1004,41 @@ class VhsHandler extends Component {
this . tech_ . src ( this . mediaSourceUrl_ ) ;
}
createKeySessions_ ( ) {
const audioPlaylistLoader =
this . masterPlaylistController_ . mediaTypes_ . AUDIO . activePlaylistLoader ;
this . logger_ ( 'waiting for EME key session creation' ) ;
waitForKeySessionCreation ( {
player : this . player_ ,
sourceKeySystems : this . source_ . keySystems ,
audioMedia : audioPlaylistLoader && audioPlaylistLoader . media ( ) ,
mainPlaylists : this . playlists . master . playlists
} ) . then ( ( ) => {
this . logger_ ( 'created EME key session' ) ;
this . masterPlaylistController_ . sourceUpdater_ . initializedEme ( ) ;
} ) . catch ( ( err ) => {
this . logger_ ( 'error while creating EME key session' , err ) ;
this . player_ . error ( {
message : 'Failed to initialize media keys for EME' ,
code : 3
} ) ;
} ) ;
}
handleWaitingForKey_ ( ) {
// If waitingforkey is fired, it's possible that the data that's necessary to retrieve
// the key is in the manifest. While this should've happened on initial source load, it
// may happen again in live streams where the keys change, and the manifest info
// reflects the update.
//
// Because videojs-contrib-eme compares the PSSH data we send to that of PSSH data it's
// already requested keys for, we don't have to worry about this generating extraneous
// requests.
this . logger_ ( 'waitingforkey fired, attempting to create any new key sessions' ) ;
this . createKeySessions_ ( ) ;
}
/ * *
* If necessary and EME is available , sets up EME options and waits for key session
* creation .
@ -1033,6 +1068,9 @@ class VhsHandler extends Component {
}
} ) ;
this . handleWaitingForKey_ = this . handleWaitingForKey_ . bind ( this ) ;
this . player_ . tech_ . on ( 'waitingforkey' , this . handleWaitingForKey_ ) ;
// In IE11 this is too early to initialize media keys, and IE11 does not support
// promises.
if ( videojs . browser . IE_VERSION === 11 || ! didSetupEmeOptions ) {
@ -1041,22 +1079,7 @@ class VhsHandler extends Component {
return ;
}
this . logger_ ( 'waiting for EME key session creation' ) ;
waitForKeySessionCreation ( {
player : this . player_ ,
sourceKeySystems : this . source_ . keySystems ,
audioMedia : audioPlaylistLoader && audioPlaylistLoader . media ( ) ,
mainPlaylists : this . playlists . master . playlists
} ) . then ( ( ) => {
this . logger_ ( 'created EME key session' ) ;
this . masterPlaylistController_ . sourceUpdater_ . initializedEme ( ) ;
} ) . catch ( ( err ) => {
this . logger_ ( 'error while creating EME key session' , err ) ;
this . player_ . error ( {
message : 'Failed to initialize media keys for EME' ,
code : 3
} ) ;
} ) ;
this . createKeySessions_ ( ) ;
}
/ * *
@ -1171,6 +1194,10 @@ class VhsHandler extends Component {
this . mediaSourceUrl_ = null ;
}
if ( this . tech_ ) {
this . tech_ . off ( 'waitingforkey' , this . handleWaitingForKey_ ) ;
}
super . dispose ( ) ;
}