Skip to content
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

Fix safari play() after source change #4639

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,13 @@ class Player extends Component {
play() {
if (this.changingSrc_) {
this.ready(function() {

// Safari struggles to play immediately following a source change
// without first calling load() if preload="none", except in desktop Safari 11
if (this.techGet_('preload') === 'none' && (browser.IS_IOS || browser.DESKTOP_SAFARI_VERSION < 11)) {
this.techCall_('load');
}

const retval = this.techGet_('play');

// silence errors (unhandled promise from play)
Expand Down
8 changes: 8 additions & 0 deletions src/js/utils/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ export const IE_VERSION = (function() {

export const IS_SAFARI = (/Safari/i).test(USER_AGENT) && !IS_CHROME && !IS_ANDROID && !IS_EDGE;
export const IS_ANY_SAFARI = IS_SAFARI || IS_IOS;
export const DESKTOP_SAFARI_VERSION = (function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should just be SAFARI_VERSION? on iOS it'll be equivalent to IOS_VERSION?
I.e., if you return IOS_VERSION instead of null from this iife.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would find it clearer to have IOS_VERSION solely responsible for mobile and DESKTOP_SAFARI_VERSION solely responsible for desktop, rather than a multi-purpose SAFARI_VERSION, but that's just me. Happy to make this change if you want me to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@videojs/core-committers any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having a separate Desktop Safari version would be more clear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think having desktop is better as well

const match = USER_AGENT.match(/Version\/(\d+)/);

if (match && match[1] && IS_SAFARI && !IS_IOS) {
return parseFloat(match[1]);
}
return null;
}());

export const TOUCH_ENABLED = Dom.isReal() && (
'ontouchstart' in window ||
Expand Down
4 changes: 4 additions & 0 deletions test/unit/tech/tech-faker.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class TechFaker extends Tech {
controls() {
return false;
}
preload() {
return 'auto';
}
load() {}

// Support everything except for "video/unsupported-format"
static isSupported() {
Expand Down