-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Automatic fullscreen videos on device roation #10108
Conversation
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.
Overall I think we can move ahead with this feature. I suggest:
1- Run through the requested changed in this PR
2- Add integration tests and do some manual testing specially to make sure:
A) orientation change when AMP doc is invisible (i.e. not the current item in the Viewer) is side-effect free.
B) ensure if video was already made fullscreen by user, this code is side-effect free.
C) ensure when we take the video to fullscreen automatically (specially iframed ones), the fullscreen UI control works as expected (e.g. user can exit fullscreen manually and that does not mess up the code logic here)
3- Validator and documentation PR when we are happy with the feature.
src/video-interface.js
Outdated
/** | ||
* auto-fullscreen | ||
* | ||
* NOTE: experimental |
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.
don't think we need to keep this experimental.
src/video-interface.js
Outdated
* auto-fullscreen | ||
* | ||
* NOTE: experimental | ||
* If enabled, this automatically expands the currently visible video to |
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.
currently visible and playing
.
Let's discuss with @spacedino on whether we need to exclude autoplaying from this behaviour or not (I don't see a reason to exclude autoplay from this feature)
src/service/video-manager-impl.js
Outdated
* @private | ||
*/ | ||
maybeInstallOrientationObserver_(entry) { | ||
// TODO(@wassgha): Remove this later. For now, the orientation observer |
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.
let's replace the TODO
with a comment that we only needs this when auto-fullscreen
is enabled. Can't think of any other cases we may need this observer.
src/service/video-manager-impl.js
Outdated
// Chrome apparently considers 'orientationchange' to be an untrusted | ||
// event, while 'change' on screen.orientation is considered a user | ||
// interaction | ||
if (screen.orientation !== undefined) { |
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.
note sue if screen
is available in all browsers (e.g. IE11) also we want to get the screen
from the current win
not the global screen
so let's do:
const screen = this.ampdoc_.win.screen;
if (screen && screen.orientation)
src/service/video-manager-impl.js
Outdated
*/ | ||
orientationChanged_() { | ||
|
||
const vidElement = this.video.element.querySelector('iframe, 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.
add TODO to refactor since video docking is using this as well.
src/service/video-manager-impl.js
Outdated
const angle = this.ampdoc_.win.orientation !== undefined ? | ||
this.ampdoc_.win.orientation : screen.orientation.angle; | ||
|
||
if (this.isVisible_ |
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.
reverse and return early (before the angel calculation). Also make sure you bail out if !viewerForDoc(this.ampdoc_).isVisible()
src/service/video-manager-impl.js
Outdated
&& (Math.abs(angle) == 270 || Math.abs(angle) == 90)) { | ||
|
||
// Determine which implementation of requestFullScreen to use | ||
const requestFullScreen = vidElement.webkitEnterFullscreen |
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.
let's refactor to two new methods on entry
: enterFullscreen_()
and exitFullscreen_()
src/service/video-manager-impl.js
Outdated
|| vidElement.webkitEnterFullscreen || vidElement.msRequestFullscreen | ||
|| vidElement.mozRequestFullScreen; | ||
|
||
requestFullScreen.call(vidElement); |
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.
try catch
these calls since we don't wanna log when request is denied, if it fails, we should not set this.isFullscreen_ = true;
src/service/video-manager-impl.js
Outdated
|
||
if (this.isVisible_ | ||
&& this.getPlayingState() == PlayingStates.PLAYING_MANUAL | ||
&& (Math.abs(angle) == 270 || Math.abs(angle) == 90)) { |
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.
what happens if user manually goes to fullscreen and then rotates in the following cases?
1- Chrome amp-video
2- Chrome amp-youtube
3- iOS amp-video
4- iOS amp-youtube
I am assuming (hoping) fullscreen request will be denied.
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.
Behaves correctly (manually tested)
src/service/video-manager-impl.js
Outdated
requestFullScreen.call(vidElement); | ||
this.isFullscreen_ = true; | ||
|
||
} else if (this.isFullscreen_) { |
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.isFullscreen_
is misleading, it is more like this.isFullscreenWithAutoFullscreen_
052cc14
to
30e88f0
Compare
@aghassemi There's an issue i'm not sure how to fix: When you're in portrait and the video is in view then you rotate the video sometimes gets out of view and therefore doesn't go to fullscreen (since we only measure whether it is visible or not after the orientation change...) |
60f7370
to
03791d2
Compare
4ea6e7f
to
26ceeb4
Compare
@aghassemi Would we want to add a |
@wassgha definitely, not hopeful that any 3P has support for this (including YT) but at minimum we can make it work for IMA |
26ceeb4
to
424abc4
Compare
8662284
to
99411a1
Compare
Ready for review :) |
a87213d
to
212b88c
Compare
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.
looks good, few nits
* @override | ||
*/ | ||
fullscreenEnter() { | ||
// TODO(@aghassemi) Make internal <video> element go fullscreen instead |
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.
Do TODO(aghassemi, #10597)
src/dom.js
Outdated
/** | ||
* Replacement for `Element.requestFullscreen()` method. | ||
* https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullscreen | ||
* @param {Element} element |
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.
{!Element}
(same below)
src/video-interface.js
Outdated
* http://caniuse.com/#feat=screen-orientation | ||
* and http://caniuse.com/#feat=fullscreen | ||
*/ | ||
AUTOFULLSCREEN: 'auto-fullscreen', |
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.
what was the conclusion from design review? fullscreen-on-landscape
or auto-fullscreen
? (I am fine with either)
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 think the consensus was to launch as default and add no-fullscreen-on-landscape
but i'm not sure about that..
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 am not a big fan of binary attributes. Let's do:
fullscreen-on-landscape=(never|always)
.
If fullscreen-on-landscape
is specified without a value, then it equals always
If no fullscreen-on-landscape
is specified, for initial launch, it means never
, we will have to do an experiment and ramp up slowly where not having fullscreen-on-landscape
starts meaning always
src/service/video-manager-impl.js
Outdated
* @private | ||
*/ | ||
orientationChanged_(isLandscape) { | ||
// Put the video in/out of fullscreen depending on orientation |
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.
return early if !viewerForDoc(this.ampdoc_).isVisible()
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.
Actually from what I've seen, when the video is fullscreen, viewerForDoc(this.ampdoc_).isVisible()
always returns false. Is that the normal behavior or is it a bug?
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.
interesting, it is technically correct. Can we ensure at least we don't go to fullscreen on rotation if viewerForDoc(this.ampdoc_).isVisible()
is false
?
src/video-interface.js
Outdated
* http://caniuse.com/#feat=screen-orientation | ||
* and http://caniuse.com/#feat=fullscreen | ||
*/ | ||
AUTOFULLSCREEN: 'auto-fullscreen', |
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.
let's also add the validation rules and documentation for all the components that now support this in a separate PR (which would effectively be the launch PR, so let's CC Eric and Rudy on that one)
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.
Do we want to switch to attribute lists on that PR or leave that for 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.
yeah would be a good time to do attribute list for video-interface
94f885f
to
03b3c1e
Compare
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.
Couple more requests and then good to merge!
@@ -218,6 +227,9 @@ class AmpDailymotion extends AMP.BaseElement { | |||
case DailymotionEvents.STARTED_BUFFERING: | |||
this.startedBufferingResolver_(true); | |||
break; | |||
case DailymotionEvents.FULLSCREEN_CHANGE: |
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.
nice! they thought of everything.
src/service/video-manager-impl.js
Outdated
* @private | ||
*/ | ||
orientationChanged_(isLandscape) { | ||
// Put the video in/out of fullscreen depending on screen orientation |
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.
return early if this.loaded_
is false
. What can happen is orientation change occurring before the layoutCallback
of a video player is called in which case their iframe
is null. Now at the moment we can't get to that case because of the this.getPlayingState() == PlayingStates.PLAYING_MANUAL
check but I like to keep the code safe since later supporting AUTOPLAY can surface the race condition.
<body> | ||
<h1>amp-video</h1> | ||
|
||
<amp-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.
just add the sample to the end of the existing amp-video.amp.html (and youtube, brid, ima, daily motion)
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.
Needs validation though...
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.
right.. then let's move this to test/manual and create an issue to add examples + ABE samples when launched.
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.
src/service/video-manager-impl.js
Outdated
VideoAttributes.FULLSCREEN_ON_LANDSCAPE | ||
); | ||
|
||
this.hasFullscreenOnLandscape = fsOnLandscapeAttr !== undefined |
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.
undefined
check not needed (getAttribute
actually returns null). Also inconsistent ==
and ===
(just use ==
compiler takes care of it).
…+ bug fixes and iOS compatibility
03b3c1e
to
d5cc3ee
Compare
d5cc3ee
to
6f76e18
Compare
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.
LGTM! Thanks!
Switching to landscape when watching a video is a strong indicator that the user wants to expand the video to fullscreen. This feature allows AMP pages to automatically put videos into fullscreen mode when an orientation change is detected.
Changes
auto-fullscreen
attribute to the video interfacefullscreenEnter
andfullscreenExit
to the video interface and implemented it for all players (amp-video
andamp-dailymotion
have full support on iOS, other video players don't for now). Opened Implement iOS-compatiblefullscreenEnter
andfullscreenExit
on video players that support it #10561 to check compatibility and implement any internal fullscreen API.Closes #5380 , Checks-off an item on #4154 , Related-to #10561 , #10660