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

Implemented Media Session API for video components #10476

Merged
merged 7 commits into from
Aug 2, 2017
Merged
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
10 changes: 10 additions & 0 deletions extensions/amp-3q-player/0.1/amp-3q-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ class Amp3QPlayer extends AMP.BaseElement {
return isFullscreenElement(dev().assertElement(this.iframe_));
}

/** @override */
getMetadata() {
// Not implemented
}

/** @override */
preimplementsMediaSessionAPI() {
return false;
}

/** @override */
getCurrentTime() {
// Not supported.
Expand Down
10 changes: 10 additions & 0 deletions extensions/amp-brid-player/0.1/amp-brid-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ class AmpBridPlayer extends AMP.BaseElement {
return isFullscreenElement(dev().assertElement(this.iframe_));
}

/** @override */
getMetadata() {
// Not implemented
}

/** @override */
preimplementsMediaSessionAPI() {
return false;
}

/** @override */
getCurrentTime() {
// Not supported.
Expand Down
10 changes: 10 additions & 0 deletions extensions/amp-dailymotion/0.1/amp-dailymotion.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ class AmpDailymotion extends AMP.BaseElement {
}
}

/** @override */
getMetadata() {
// Not implemented
}

/** @override */
preimplementsMediaSessionAPI() {
return false;
}

/** @override */
getCurrentTime() {
// Not supported.
Expand Down
10 changes: 10 additions & 0 deletions extensions/amp-ima-video/0.1/amp-ima-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ class AmpImaVideo extends AMP.BaseElement {
return isFullscreenElement(dev().assertElement(this.iframe_));
}

/** @override */
getMetadata() {
// Not implemented
}

/** @override */
preimplementsMediaSessionAPI() {
return false;
}

/** @override */
getCurrentTime() {
// Not supported.
Expand Down
10 changes: 10 additions & 0 deletions extensions/amp-nexxtv-player/0.1/amp-nexxtv-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ class AmpNexxtvPlayer extends AMP.BaseElement {
return isFullscreenElement(dev().assertElement(this.iframe_));
}

/** @override */
getMetadata() {
// Not implemented
}

/** @override */
preimplementsMediaSessionAPI() {
return false;
}

/** @override */
getCurrentTime() {
// Not supported.
Expand Down
10 changes: 10 additions & 0 deletions extensions/amp-ooyala-player/0.1/amp-ooyala-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ class AmpOoyalaPlayer extends AMP.BaseElement {
return isFullscreenElement(dev().assertElement(this.iframe_));
}

/** @override */
getMetadata() {
// Not implemented
}

/** @override */
preimplementsMediaSessionAPI() {
return false;
}

/** @override */
getCurrentTime() {
// Not supported.
Expand Down
74 changes: 47 additions & 27 deletions extensions/amp-video/0.1/amp-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ const ATTRS_TO_PROPAGATE =
*/
class AmpVideo extends AMP.BaseElement {

/**
* @param {!AmpElement} element
*/
/**
* @param {!AmpElement} element
*/
constructor(element) {
super(element);

/** @private {?Element} */
/** @private {?Element} */
this.video_ = null;

/** @private {?boolean} */
/** @private {?boolean} */
this.muted_ = false;
}

/**
* @param {boolean=} opt_onLayout
* @override
*/
/**
* @param {boolean=} opt_onLayout
* @override
*/
preconnectCallback(opt_onLayout) {
const videoSrc = this.getVideoSource_();
if (videoSrc) {
Expand All @@ -84,10 +84,10 @@ class AmpVideo extends AMP.BaseElement {
}
}

/**
* @private
* @return {string}
*/
/**
* @private
* @return {string}
*/
getVideoSource_() {
let videoSrc = this.element.getAttribute('src');
if (!videoSrc) {
Expand All @@ -99,12 +99,12 @@ class AmpVideo extends AMP.BaseElement {
return videoSrc;
}

/** @override */
/** @override */
isLayoutSupported(layout) {
return isLayoutSizeDefined(layout);
}

/** @override */
/** @override */
buildCallback() {
this.video_ = this.element.ownerDocument.createElement('video');

Expand All @@ -114,10 +114,10 @@ class AmpVideo extends AMP.BaseElement {
'No "poster" attribute has been provided for amp-video.');
}

// Enable inline play for iOS.
// Enable inline play for iOS.
this.video_.setAttribute('playsinline', '');
this.video_.setAttribute('webkit-playsinline', '');
// Disable video preload in prerender mode.
// Disable video preload in prerender mode.
this.video_.setAttribute('preload', 'none');
this.propagateAttributes(ATTRS_TO_PROPAGATE_ON_BUILD, this.video_,
/* opt_removeMissingAttrs */ true);
Expand All @@ -129,7 +129,7 @@ class AmpVideo extends AMP.BaseElement {
Services.videoManagerForDoc(this.element).register(this);
}

/** @override */
/** @override */
mutatedAttributesCallback(mutations) {
if (!this.video_) {
return;
Expand All @@ -148,12 +148,12 @@ class AmpVideo extends AMP.BaseElement {
}
}

/** @override */
/** @override */
viewportCallback(visible) {
this.element.dispatchCustomEvent(VideoEvents.VISIBILITY, {visible});
}

/** @override */
/** @override */
layoutCallback() {
this.video_ = dev().assertElement(this.video_);

Expand All @@ -170,7 +170,7 @@ class AmpVideo extends AMP.BaseElement {
/* opt_removeMissingAttrs */ true);

this.getRealChildNodes().forEach(child => {
// Skip the video we already added to the element.
// Skip the video we already added to the element.
if (this.video_ === child) {
return;
}
Expand All @@ -181,7 +181,7 @@ class AmpVideo extends AMP.BaseElement {
this.video_.appendChild(child);
});

// loadPromise for media elements listens to `loadstart`
// loadPromise for media elements listens to `loadstart`
return this.loadPromise(this.video_).then(() => {
this.element.dispatchCustomEvent(VideoEvents.LOAD);
});
Expand Down Expand Up @@ -241,11 +241,11 @@ class AmpVideo extends AMP.BaseElement {

if (ret && ret.catch) {
ret.catch(() => {
// Empty catch to prevent useless unhandled promise rejection logging.
// Play can fail for many reasons such as video getting paused before
// play() is finished.
// We use events to know the state of the video and do not care about
// the success or failure of the play()'s returned promise.
// Empty catch to prevent useless unhandled promise rejection logging.
// Play can fail for many reasons such as video getting paused before
// play() is finished.
// We use events to know the state of the video and do not care about
// the success or failure of the play()'s returned promise.
});
}
}
Expand Down Expand Up @@ -304,6 +304,26 @@ class AmpVideo extends AMP.BaseElement {
return isFullscreenElement(dev().assertElement(this.video_));
}

/** @override */
getMetadata() {
const poster = this.element.getAttribute('poster');
if (poster) {
return {
'title': '',
'artist': '',
'album': '',
'artwork': [
{'src': poster},
],
};
}
}

/** @override */
preimplementsMediaSessionAPI() {
return false;
}

/** @override */
getCurrentTime() {
return this.video_.currentTime;
Expand Down
12 changes: 12 additions & 0 deletions extensions/amp-youtube/0.1/amp-youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,18 @@ class AmpYoutube extends AMP.BaseElement {
return isFullscreenElement(dev().assertElement(this.iframe_));
}

/** @override */
getMetadata() {
// Not implemented
}

/** @override */
preimplementsMediaSessionAPI() {
// Youtube already updates the Media Session so no need for the video
// manager to update it too
return true;
}

/** @override */
getCurrentTime() {
// Not supported.
Expand Down
Loading