-
Notifications
You must be signed in to change notification settings - Fork 116
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
New: add autoplay to media viewers #433
Conversation
*/ | ||
handleAutoplay() { | ||
const isAutoplayEnabled = | ||
this.cache.has(MEDIA_AUTOPLAY_CACHE_KEY) && this.cache.get(MEDIA_AUTOPLAY_CACHE_KEY) === 'Enabled'; |
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.
I don't think you have to do the first check. get()
in Cache.js already does a check
*/ | ||
checkAutoplay() { | ||
if ( | ||
(!this.cache.has(MEDIA_AUTOPLAY_CACHE_KEY) || this.cache.get(MEDIA_AUTOPLAY_CACHE_KEY) === 'Disabled') && |
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 code implies if nothing is set in the cache, then don't autoplay. Is that what you want? (I think so?)
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.
Yep, I'll add a clarifying comment.
|
||
// iOS doesn't fire loadeddata event until some data loads | ||
// Adding autoplay prevents that, but iOS Safari won't autoplay media | ||
// https://webkit.org/blog/6784/new-video-policies-for-ios/ |
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.
I'd move this comment above the return check
// iOS doesn't fire loadeddata event until some data loads | ||
// Adding autoplay prevents that, but iOS Safari won't autoplay media | ||
// https://webkit.org/blog/6784/new-video-policies-for-ios/ | ||
this.mediaEl.autoplay = true; |
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.
Could this be triggered when the media element isn't loaded yet?
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 should be set before the media element is loaded. From MDN: A Boolean attribute; if specified, the video automatically begins to play back as soon as it can do so without stopping to finish loading the data.
@@ -321,6 +368,7 @@ class MediaBaseViewer extends BaseViewer { | |||
this.hideLoadingIcon(); | |||
this.handleRate(); | |||
this.handleVolume(); | |||
this.emit('play'); |
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.
Moved this here so that all autoplay related plays also emit.
@@ -107,6 +108,7 @@ class MediaBaseViewer extends BaseViewer { | |||
.getPromise() | |||
.then(() => { | |||
this.mediaEl.src = this.mediaUrl; | |||
this.checkAutoplay(); |
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.
Added this after the src is set because doing so can disrupt play. Noted here: https://webkit.org/blog/7734/auto-play-policy-changes-for-macos/
@@ -160,6 +182,11 @@ class Settings extends EventEmitter { | |||
addActivationListener(this.settingsEl, this.menuEventHandler); | |||
this.containerEl.classList.add(CLASS_SETTINGS_SUBTITLES_UNAVAILABLE); | |||
this.containerEl.classList.add(CLASS_SETTINGS_AUDIOTRACKS_UNAVAILABLE); | |||
|
|||
if (Browser.isIOS()) { |
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.
Autoplay is not supported on iOS.
No description provided.