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

VideoPress: Add video settings to the VideoPress-enhanced video block #13134

Merged
merged 5 commits into from
Aug 7, 2019

Conversation

mmtr
Copy link
Member

@mmtr mmtr commented Jul 26, 2019

Fixes #11837.

Changes proposed in this Pull Request:

This PR adds the video settings allowing to customize several options for the VideoPress player rendered by the video block (extended by our VideoPress extension for Gutenberg).

screen shot 2019-02-14 at 10 05 29 am

Now, after inserting a VideoPress-enhanced video block, a user can set the following settings:

  • Autoplay: whether to start playing as soon as the player renders (note that some browsers can prevent a video from being autoplayed).
  • Loop: whether to loop the video.
  • Muted: whether the video should start in a muted state.
  • Playback controls: whether show the controls to allow the user to control video playback.
  • Preload: what content is loaded before the video is played:
    • None: Indicates that the video should not be preloaded.
    • Metadata: Indicates that only video metadata (e.g. length) is fetched.
    • Auto: Indicates that the whole video file can be downloaded, even if the user is not expected to use it.
  • Poster image: image to be shown while the video is downloading.

Given that these settings modifies the URL saved in the block content, any existing post containing a VideoPress-enhanced video block would result in a "invalid content" error. In order to support those posts, a deprecated version of the block has been added.

This PR also introduces a new playsInline attribute (added in core in WordPress/gutenberg#14500), but it's currently unmodifiable, since VideoPress doesn't support it yet.

Is this a new feature or does it add/remove features to an existing part of Jetpack?

See pafL3P-cU-p2 (Phase 3).

Testing instructions:

  • Create a new JN site using this branch.
  • Connect to WP.com using a premium subscription.
  • Go to Jetpack → Settings → Performance and activate the VideoPress module (by enabling the "Enable high-speed, ad-free video player" option).
  • Go to Posts → New.
  • Insert a video block.
  • Upload or select an existing video.
  • Make sure the VideoPress player is previewed on the editor.
  • Make sure the video settings appear in the sidebar.
  • Set any video setting you like.
  • Make sure the previewed player reflects the video settings you have set.
  • Publish the post.
  • Check the published view and verify the player reflects the video settings you have set in the editor.

Proposed changelog entry for your changes:

  • VideoPress: Add video settings to the VideoPress-enhanced video block.

@mmtr mmtr added [Feature] VideoPress A feature to help you upload and insert videos on your site. [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack labels Jul 26, 2019
@mmtr mmtr requested review from a team July 26, 2019 05:04
@mmtr mmtr self-assigned this Jul 26, 2019
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello mmtr! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D30868-code before merging this PR. Thank you!

@jetpackbot
Copy link

jetpackbot commented Jul 26, 2019

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: August 6, 2019.
Scheduled code freeze: July 30, 2019

Generated by 🚫 dangerJS against 765e372

@gwwar
Copy link
Contributor

gwwar commented Jul 26, 2019

Hmm @mmtr looks like tests are failing in D30868-code from a timeout. Is there a way of triggering another run?

gwwar
gwwar previously approved these changes Jul 26, 2019
Copy link
Contributor

@gwwar gwwar left a comment

Choose a reason for hiding this comment

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

Nice work @mmtr! I always ❤️ the detailed testing instructions.

I smoke tested on a Jetpack site with various combinations of settings applied. No errors on second edit.

I think folks can get a video that doesn't play if they turn off controls / don't have autoplay/loop on, but I think we allowed the before.

@mmtr
Copy link
Member Author

mmtr commented Jul 26, 2019

Hmm @mmtr looks like tests are failing in D30868-code from a timeout. Is there a way of triggering another run?

I just restarted the build in the diff. Let's see if they pass now.

@mmtr
Copy link
Member Author

mmtr commented Jul 27, 2019

Just realized that the deprecated version included on this PR doesn't work when using the latest Gutenberg plugin version due to the changes introduced by WordPress/gutenberg#16348.

To reproduce the problem:

  • Install and activate the latest version of the Gutenberg plugin.
  • Open an existing post containing a video block that has been inserted with the current codebase of the master branch.
  • The block will trigger an invalid content error:

Screen Shot 2019-07-27 at 13 52 54

Will investigate if the deprecations should be defined in a different way.

Pinging @talldan @epiqueras @youknowriad as well, since they seem to have been involved in the recents changes for deprecations.

@matticbot
Copy link
Contributor

mmtr, Your synced wpcom patch D30868-code has been updated.

@mmtr
Copy link
Member Author

mmtr commented Jul 27, 2019

Just realized that the deprecated version included on this PR doesn't work when using the latest Gutenberg plugin version due to the changes introduced by WordPress/gutenberg#16348.

Noted that this is caused by the deprecations returned by the blocks.registerBlocks filter used in the VideoPress extension to customize the core/video block.

After WordPress/gutenberg#16348, the deprecations now trigger the blocks.registerBlocks filter too, so our VideoPress extension was changing the original deprecations.

Added a workaround in 6a89012 that ensures that our extension doesn't run when the blocks.registerBlocks filter is triggered by a deprecation.

@epiqueras
Copy link

Added a workaround in 6a89012 that ensures that our extension doesn't run when the blocks.registerBlocks filter is triggered by a deprecation.

@youknowriad @talldan Maybe we should provide a way for the filter to infer whether it's running on a deprecation or not.

@jeherve jeherve added this to the 7.7 milestone Jul 29, 2019
@gwwar
Copy link
Contributor

gwwar commented Jul 30, 2019

I verified that this no longer breaks existing video blocks on edit. @mmtr is setting the poster image working for you from wp-admin?

@mmtr
Copy link
Member Author

mmtr commented Jul 31, 2019

@mmtr is setting the poster image working for you from wp-admin?

Yup, but I noted that the previewed video player doesn't reflect always the settings I defined on the sidebar. Seems to be the same behavior as noted by @kwight at D30868-code#616950.

However, the player that appears on the published view is always correct. Will try to determine what's causing this.

@mmtr
Copy link
Member Author

mmtr commented Jul 31, 2019

Yup, but I noted that the previewed video player doesn't reflect always the settings I defined on the sidebar. Seems to be the same behavior as noted by @kwight at D30868-code#616950.

However, the player that appears on the published view is always correct. Will try to determine what's causing this.

Turned out to be a bug in core caused by the SandBox component not being re-rendered when the injected HTML changes: WordPress/gutenberg#16831

We render a SandBox component to embed the preview.

Note that his only happens when we want to preview a URL that was already previewed before, since these previews are cached, so the block doesn't render the "Generating preview..." placeholder and will keep using the same SandBox component that was rendered before.

If the preview has never been generated, the block will render first the "Generating preview..." placeholder and then a new instance of the SandBox component, where the above issue is not present given the component has been freshly rendered.

I'm not sure if there is any workaround for this (AFAIK we cannot force a re-rendering of a child component from the parent), but if this is a blocker we could try something like invalidating the cached previews, so we make sure we render a new instance of the SandBox component every time.

@simison
Copy link
Member

simison commented Jul 31, 2019

Please rebase with #12926

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Jul 31, 2019
@mmtr
Copy link
Member Author

mmtr commented Aug 1, 2019

I'm not sure if there is any workaround for this (AFAIK we cannot force a re-rendering of a child component from the parent), but if this is a blocker we could try something like invalidating the cached previews, so we make sure we render a new instance of the SandBox component every time.

Added a workaround in ac48fe8 that invalidates the cached previews before generating a new one.

@youknowriad
Copy link

@youknowriad @talldan Maybe we should provide a way for the filter to infer whether it's running on a deprecation or not.

This sounds reasonable to me.

@talldan
Copy link
Contributor

talldan commented Aug 1, 2019

Sorry for not responding, must have missed the notification. I'll work on a PR in gutenberg for this, shouldn't take long to implement.

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This is pretty cool, I love that it works for both local videos and VideoPress videos, nice work!

It tests well, I only found issues with VideoPress videos, when flipping one toggle and then turning it off. If you do that with the Mute toggle for example, &muted=true is added to the URL, and then it is switched to &muted=false.

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Aug 1, 2019
@matticbot
Copy link
Contributor

mmtr, Your synced wpcom patch D30868-code has been updated.

@mmtr
Copy link
Member Author

mmtr commented Aug 2, 2019

Thanks for that suggestion @jeherve! Actually it makes sense to don't include any setting in the URL that will have the same effect as the default player, so the URL will look cleaner.

I applied some changes in 765e372 based on that approach, and now the VideoPress URLs will contain only the parameters having a value that differs from the default VideoPress player settings.

@mmtr mmtr added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Aug 2, 2019
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This works better now, everything appears to be working for me right now, except for autoplay; does it work for you?

https://videopress.com/v/gj2bX2G4?autoPlay=true&loop=true&muted=true&persistVolume=false&preloadContent=metadata

I tried in both Chrome and Firefox. Do those browsers not allow autoplay at all?

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Aug 2, 2019
@kwight
Copy link
Contributor

kwight commented Aug 2, 2019

The video is muted as soon as you have the parameter, regardless of its value

This seems to be the intended behaviour, for the autoplay attribute too: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video. Removing the value will also clear up the inconsistency of true/false vs. 1/0 (eg. currently setting both autoplay and mute will give muted="true" autoplay="1").

everything appears to be working for me right now, except for autoplay; does it work for you?

I can't get autoplay to work at all in Chrome. This post implies that having both mute and autoplay active should enable autoplay, but this wasn't my experience (their other mentioned situations that allow autoplay didn't work for me either; and the post is old, but it was recently updated). Oddly enough, Firefox did behave that way; I could leave autoplay on, then toggle its effectiveness with the mute setting. It seems like browsers are all a bit inconsistent; since we've been able to determine each setting works as expected in at least one browser, we probably shouldn't hold up the PR on it 🙃

@mmtr I'm still having problems with the editor preview though; I can't interact with it directly at all ¯_(ツ)_/¯

@kwight
Copy link
Contributor

kwight commented Aug 2, 2019

@mmtr I'm still having problems with the editor preview though; I can't interact with it directly at all ¯_(ツ)_/¯

Oh! Sorry, just saw your comment in D30868-code:

This is expected because we deliberately disable the video player so users don't interact accidentally with it when they want to focus the block (#). Gutenberg also does the same with the default core/video block (#).

You can interact with the player when adding the video via URL because Gutenberg doesn't render the Disabled component on core/embed blocks (core/video blocks are transformed to core/embed when using URLs).

@mmtr
Copy link
Member Author

mmtr commented Aug 2, 2019

This works better now, everything appears to be working for me right now, except for autoplay; does it work for you?

It's not working for me in Chrome but it is in Firefox as long as the video is muted, as @kwight mentioned. Not sure why is not autoplayed in Chrome, since the video element has both the autoplay and muted attributes required by the Chrome's autoplay policies:

Screen Shot 2019-08-03 at 08 19 18

Definitely not an issue on this PR and something we could investigate in the JavaScript API for VideoPress: https://github.com/Automattic/videopress/issues/38

@mmtr mmtr added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Aug 2, 2019
@mmtr mmtr merged commit 57ed23f into master Aug 7, 2019
@mmtr mmtr deleted the update/11837-videopress-block-settings branch August 7, 2019 05:42
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Aug 7, 2019
jeherve added a commit that referenced this pull request Aug 23, 2019
jeherve added a commit that referenced this pull request Aug 27, 2019
* 7.7 changelog: initial set of changes

* Changelog: add #13154

* Changelog: add #13134

* Changelog: add #12699 and many others

* Changelog: add #13127

* Changelog: add #13167

* Changelog: add #13225

* Changelog: add #13179

* Changelog: add #13173

* Changelog: add #13232

* Changelog: add #13137

* Changelog: add #13172

* Changelog: add #13182

* Changelog: add #13200

* Changelog: add #13244

* Changelog: add #13267

* Changelog: add #13204

* changelog: add #13205

* Changelog: add #13183

* Changelog: add #13278

* Changelog: add #13162

* Changelog: add #13268

* Changelog: add #13286

* Changelog: add #13273

* Changelog: add #12474

* Changelog: add #13085

* Changelog: add #13266

* Changelog: add #13306

* Changelog: add #13311

* Changelog: add #13302

* Changelog: add #13196

* Changelog: add #12733

* Changelog: add #13261

* Changelog: add #13322

* Changelog: add #13333

* Changelog: add #13335
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] VideoPress A feature to help you upload and insert videos on your site. [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack Touches WP.com Files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VideoPress: Add block video settings
10 participants