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

New: add autoplay to media viewers #433

Merged
merged 6 commits into from
Oct 24, 2017
Merged

New: add autoplay to media viewers #433

merged 6 commits into from
Oct 24, 2017

Conversation

jeremypress
Copy link
Contributor

No description provided.

*/
handleAutoplay() {
const isAutoplayEnabled =
this.cache.has(MEDIA_AUTOPLAY_CACHE_KEY) && this.cache.get(MEDIA_AUTOPLAY_CACHE_KEY) === 'Enabled';
Copy link
Contributor

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') &&
Copy link
Contributor

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?)

Copy link
Contributor Author

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/
Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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');
Copy link
Contributor Author

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();
Copy link
Contributor Author

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()) {
Copy link
Contributor Author

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.

@jeremypress jeremypress merged commit 10982de into box:master Oct 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants