-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Unify audioOnly mode and audioPoster mode #7678
Merged
misteroneill
merged 9 commits into
videojs:main
from
harisha-swaminathan:feat/audioOnlyModes
Mar 17, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a977284
unify audioOnlyMode and audioPosterMode
harisha-swaminathan f057c4d
remove console log statement
harisha-swaminathan c151709
rewrite audioPoterMode method and add tests
harisha-swaminathan f1c279b
add tests
harisha-swaminathan 6331f2d
update tests, add comments and replace currentSource with currentType
harisha-swaminathan 2f17c4a
Fix typo in comment
harisha-swaminathan b7e4e4e
Merge branch 'videojs:main' into feat/audioOnlyModes
harisha-swaminathan 6edb802
fix assert.equal/assert.ok in tests
harisha-swaminathan 1cecdfe
add comment for audio detection
harisha-swaminathan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,6 +398,9 @@ class Player extends Component { | |
// Init state audioOnlyMode_ | ||
this.audioOnlyMode_ = false; | ||
|
||
// Init state audioPosterMode_ | ||
this.audioPosterMode_ = false; | ||
|
||
// Init state audioOnlyCache_ | ||
this.audioOnlyCache_ = { | ||
playerHeight: null, | ||
|
@@ -583,7 +586,15 @@ class Player extends Component { | |
|
||
this.breakpoints(this.options_.breakpoints); | ||
this.responsive(this.options_.responsive); | ||
this.audioOnlyMode(this.options_.audioOnlyMode); | ||
|
||
// Calling both the audio mode methods after the player is fully | ||
// setup to be able to listen to the events triggered by them | ||
this.on('ready', () => { | ||
// Calling the audioPosterMode method first so that | ||
// the audioOnlyMode can take precedence when both options are set to true | ||
this.audioPosterMode(this.options_.audioPosterMode); | ||
this.audioOnlyMode(this.options_.audioOnlyMode); | ||
}); | ||
} | ||
|
||
/** | ||
|
@@ -4303,11 +4314,6 @@ class Player extends Component { | |
return !!this.isAudio_; | ||
} | ||
|
||
updateAudioOnlyModeState_(value) { | ||
this.audioOnlyMode_ = value; | ||
this.trigger('audioonlymodechange'); | ||
} | ||
|
||
enableAudioOnlyUI_() { | ||
// Update styling immediately to show the control bar so we can get its height | ||
this.addClass('vjs-audio-only-mode'); | ||
|
@@ -4334,7 +4340,7 @@ class Player extends Component { | |
|
||
// Set the player height the same as the control bar | ||
this.height(controlBarHeight); | ||
this.updateAudioOnlyModeState_(true); | ||
this.trigger('audioonlymodechange'); | ||
} | ||
|
||
disableAudioOnlyUI_() { | ||
|
@@ -4345,7 +4351,7 @@ class Player extends Component { | |
|
||
// Reset player height | ||
this.height(this.audioOnlyCache_.playerHeight); | ||
this.updateAudioOnlyModeState_(false); | ||
this.trigger('audioonlymodechange'); | ||
} | ||
|
||
/** | ||
|
@@ -4366,6 +4372,8 @@ class Player extends Component { | |
return this.audioOnlyMode_; | ||
} | ||
|
||
this.audioOnlyMode_ = value; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this here because |
||
const PromiseClass = this.options_.Promise || window.Promise; | ||
|
||
if (PromiseClass) { | ||
|
@@ -4382,6 +4390,10 @@ class Player extends Component { | |
exitPromises.push(this.exitFullscreen()); | ||
} | ||
|
||
if (this.audioPosterMode()) { | ||
exitPromises.push(this.audioPosterMode(false)); | ||
} | ||
|
||
return PromiseClass.all(exitPromises).then(() => this.enableAudioOnlyUI_()); | ||
} | ||
|
||
|
@@ -4404,35 +4416,80 @@ class Player extends Component { | |
} | ||
} | ||
|
||
enablePosterModeUI_() { | ||
// Hide the video element and show the poster image to enable posterModeUI | ||
const tech = this.tech_ && this.tech_; | ||
|
||
tech.hide(); | ||
this.addClass('vjs-audio-poster-mode'); | ||
this.trigger('audiopostermodechange'); | ||
} | ||
|
||
disablePosterModeUI_() { | ||
// Show the video element and hide the poster image to disable posterModeUI | ||
const tech = this.tech_ && this.tech_; | ||
|
||
tech.show(); | ||
this.removeClass('vjs-audio-poster-mode'); | ||
this.trigger('audiopostermodechange'); | ||
} | ||
|
||
/** | ||
* Get the current audioPosterMode state or set audioPosterMode to true or false | ||
* | ||
* @param {boolean} [value] | ||
* The value to set audioPosterMode to. | ||
* | ||
* @return {boolean} | ||
* True if audioPosterMode is on, false otherwise. | ||
* @return {Promise|boolean} | ||
* A Promise is returned when setting the state, and a boolean when getting | ||
* the present state | ||
*/ | ||
audioPosterMode(value) { | ||
|
||
if (this.audioPosterMode_ === undefined) { | ||
this.audioPosterMode_ = this.options_.audioPosterMode; | ||
} | ||
|
||
if (typeof value !== 'boolean' || value === this.audioPosterMode_) { | ||
return this.audioPosterMode_; | ||
} | ||
|
||
this.audioPosterMode_ = value; | ||
|
||
if (this.audioPosterMode_) { | ||
this.tech_.hide(); | ||
this.addClass('vjs-audio-poster-mode'); | ||
const PromiseClass = this.options_.Promise || window.Promise; | ||
|
||
if (PromiseClass) { | ||
|
||
if (value) { | ||
|
||
if (this.audioOnlyMode()) { | ||
const audioOnlyModePromise = this.audioOnlyMode(false); | ||
|
||
return audioOnlyModePromise.then(() => { | ||
// enable audio poster mode after audio only mode is disabled | ||
this.enablePosterModeUI_(); | ||
}); | ||
} | ||
|
||
return PromiseClass.resolve().then(() => { | ||
// enable audio poster mode | ||
this.enablePosterModeUI_(); | ||
}); | ||
} | ||
|
||
return PromiseClass.resolve().then(() => { | ||
// disable audio poster mode | ||
this.disablePosterModeUI_(); | ||
}); | ||
} | ||
|
||
if (value) { | ||
|
||
if (this.audioOnlyMode()) { | ||
this.audioOnlyMode(false); | ||
} | ||
|
||
this.enablePosterModeUI_(); | ||
return; | ||
} | ||
// Show the video element and hide the poster image if audioPosterMode is set to false | ||
this.tech_.show(); | ||
this.removeClass('vjs-audio-poster-mode'); | ||
|
||
this.disablePosterModeUI_(); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wouldn't work for audio-only HLS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not meant to, but perhaps that's worth adding a comment on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure whether anyone actually uses it, but
audio/mpegurl
is a valid type for HLS. I believe it's valid for HLS even if it contains video.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the-more-you-know.gif
Yeah, I should be more clear here: the intent is merely to detect cases where we know the media is audio. For HLS or DASH audio-only streams, they may have a blank video track or no video track. Either way, VHS currently does not have a way to detect whether a stream is audio only.
So, we decided that the best course of action for the time being is to do the simple detection we can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory
videoHeight()
would be enough to know there's no video - but I can see getting into a situation where there seems to be no video initially when there eventually will be. Fair enough if it doesn't cover all cases, but comment/doc would be good so that's clearer down the line.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @harisha-swaminathan!