@@ -398,6 +398,9 @@ class Player extends Component {
398
398
// Init state audioOnlyMode_
399
399
this . audioOnlyMode_ = false ;
400
400
401
+ // Init state audioPosterMode_
402
+ this . audioPosterMode_ = false ;
403
+
401
404
// Init state audioOnlyCache_
402
405
this . audioOnlyCache_ = {
403
406
playerHeight : null ,
@@ -583,7 +586,15 @@ class Player extends Component {
583
586
584
587
this . breakpoints ( this . options_ . breakpoints ) ;
585
588
this . responsive ( this . options_ . responsive ) ;
586
- this . audioOnlyMode ( this . options_ . audioOnlyMode ) ;
589
+
590
+ // Calling both the audio mode methods after the player is fully
591
+ // setup to be able to listen to the events triggered by them
592
+ this . on ( 'ready' , ( ) => {
593
+ // Calling the audioPosterMode method first so that
594
+ // the audioOnlyMode can take precedence when both options are set to true
595
+ this . audioPosterMode ( this . options_ . audioPosterMode ) ;
596
+ this . audioOnlyMode ( this . options_ . audioOnlyMode ) ;
597
+ } ) ;
587
598
}
588
599
589
600
/**
@@ -4303,11 +4314,6 @@ class Player extends Component {
4303
4314
return ! ! this . isAudio_ ;
4304
4315
}
4305
4316
4306
- updateAudioOnlyModeState_ ( value ) {
4307
- this . audioOnlyMode_ = value ;
4308
- this . trigger ( 'audioonlymodechange' ) ;
4309
- }
4310
-
4311
4317
enableAudioOnlyUI_ ( ) {
4312
4318
// Update styling immediately to show the control bar so we can get its height
4313
4319
this . addClass ( 'vjs-audio-only-mode' ) ;
@@ -4334,7 +4340,7 @@ class Player extends Component {
4334
4340
4335
4341
// Set the player height the same as the control bar
4336
4342
this . height ( controlBarHeight ) ;
4337
- this . updateAudioOnlyModeState_ ( true ) ;
4343
+ this . trigger ( 'audioonlymodechange' ) ;
4338
4344
}
4339
4345
4340
4346
disableAudioOnlyUI_ ( ) {
@@ -4345,7 +4351,7 @@ class Player extends Component {
4345
4351
4346
4352
// Reset player height
4347
4353
this . height ( this . audioOnlyCache_ . playerHeight ) ;
4348
- this . updateAudioOnlyModeState_ ( false ) ;
4354
+ this . trigger ( 'audioonlymodechange' ) ;
4349
4355
}
4350
4356
4351
4357
/**
@@ -4366,6 +4372,8 @@ class Player extends Component {
4366
4372
return this . audioOnlyMode_ ;
4367
4373
}
4368
4374
4375
+ this . audioOnlyMode_ = value ;
4376
+
4369
4377
const PromiseClass = this . options_ . Promise || window . Promise ;
4370
4378
4371
4379
if ( PromiseClass ) {
@@ -4382,6 +4390,10 @@ class Player extends Component {
4382
4390
exitPromises . push ( this . exitFullscreen ( ) ) ;
4383
4391
}
4384
4392
4393
+ if ( this . audioPosterMode ( ) ) {
4394
+ exitPromises . push ( this . audioPosterMode ( false ) ) ;
4395
+ }
4396
+
4385
4397
return PromiseClass . all ( exitPromises ) . then ( ( ) => this . enableAudioOnlyUI_ ( ) ) ;
4386
4398
}
4387
4399
@@ -4404,35 +4416,80 @@ class Player extends Component {
4404
4416
}
4405
4417
}
4406
4418
4419
+ enablePosterModeUI_ ( ) {
4420
+ // Hide the video element and show the poster image to enable posterModeUI
4421
+ const tech = this . tech_ && this . tech_ ;
4422
+
4423
+ tech . hide ( ) ;
4424
+ this . addClass ( 'vjs-audio-poster-mode' ) ;
4425
+ this . trigger ( 'audiopostermodechange' ) ;
4426
+ }
4427
+
4428
+ disablePosterModeUI_ ( ) {
4429
+ // Show the video element and hide the poster image to disable posterModeUI
4430
+ const tech = this . tech_ && this . tech_ ;
4431
+
4432
+ tech . show ( ) ;
4433
+ this . removeClass ( 'vjs-audio-poster-mode' ) ;
4434
+ this . trigger ( 'audiopostermodechange' ) ;
4435
+ }
4436
+
4407
4437
/**
4408
4438
* Get the current audioPosterMode state or set audioPosterMode to true or false
4409
4439
*
4410
4440
* @param {boolean } [value]
4411
4441
* The value to set audioPosterMode to.
4412
4442
*
4413
- * @return {boolean }
4414
- * True if audioPosterMode is on, false otherwise.
4443
+ * @return {Promise|boolean }
4444
+ * A Promise is returned when setting the state, and a boolean when getting
4445
+ * the present state
4415
4446
*/
4416
4447
audioPosterMode ( value ) {
4417
4448
4418
- if ( this . audioPosterMode_ === undefined ) {
4419
- this . audioPosterMode_ = this . options_ . audioPosterMode ;
4420
- }
4421
-
4422
4449
if ( typeof value !== 'boolean' || value === this . audioPosterMode_ ) {
4423
4450
return this . audioPosterMode_ ;
4424
4451
}
4425
4452
4426
4453
this . audioPosterMode_ = value ;
4427
4454
4428
- if ( this . audioPosterMode_ ) {
4429
- this . tech_ . hide ( ) ;
4430
- this . addClass ( 'vjs-audio-poster-mode' ) ;
4455
+ const PromiseClass = this . options_ . Promise || window . Promise ;
4456
+
4457
+ if ( PromiseClass ) {
4458
+
4459
+ if ( value ) {
4460
+
4461
+ if ( this . audioOnlyMode ( ) ) {
4462
+ const audioOnlyModePromise = this . audioOnlyMode ( false ) ;
4463
+
4464
+ return audioOnlyModePromise . then ( ( ) => {
4465
+ // enable audio poster mode after audio only mode is disabled
4466
+ this . enablePosterModeUI_ ( ) ;
4467
+ } ) ;
4468
+ }
4469
+
4470
+ return PromiseClass . resolve ( ) . then ( ( ) => {
4471
+ // enable audio poster mode
4472
+ this . enablePosterModeUI_ ( ) ;
4473
+ } ) ;
4474
+ }
4475
+
4476
+ return PromiseClass . resolve ( ) . then ( ( ) => {
4477
+ // disable audio poster mode
4478
+ this . disablePosterModeUI_ ( ) ;
4479
+ } ) ;
4480
+ }
4481
+
4482
+ if ( value ) {
4483
+
4484
+ if ( this . audioOnlyMode ( ) ) {
4485
+ this . audioOnlyMode ( false ) ;
4486
+ }
4487
+
4488
+ this . enablePosterModeUI_ ( ) ;
4431
4489
return ;
4432
4490
}
4433
- // Show the video element and hide the poster image if audioPosterMode is set to false
4434
- this . tech_ . show ( ) ;
4435
- this . removeClass ( 'vjs-audio-poster-mode' ) ;
4491
+
4492
+ this . disablePosterModeUI_ ( ) ;
4436
4493
}
4437
4494
4438
4495
/**
0 commit comments