Skip to content

Commit

Permalink
Implemented (empty) metadata and mediasession api for all players & a…
Browse files Browse the repository at this point in the history
…dded better default posters
  • Loading branch information
wassgha committed Jul 24, 2017
1 parent 32d166a commit dbadc6b
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 77 deletions.
15 changes: 15 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 @@ -215,6 +215,21 @@ class Amp3QPlayer extends AMP.BaseElement {
this.sdnPostMessage_('hideControlbar');
}

/** @override */
getMetaData() {
return {
'artwork': [],
'title': '',
'artist': '',
'album': '',
};
}

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

/** @override */
getCurrentTime() {
// Not supported.
Expand Down
15 changes: 15 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 @@ -286,6 +286,21 @@ class AmpBridPlayer extends AMP.BaseElement {
// Not supported.
}

/** @override */
getMetaData() {
return {
'artwork': [],
'title': '',
'artist': '',
'album': '',
};
}

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

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

/** @override */
getMetaData() {
return {
'artwork': [],
'title': '',
'artist': '',
'album': '',
};
}

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

/** @override */
getCurrentTime() {
// Not supported.
Expand Down
15 changes: 15 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 @@ -273,6 +273,21 @@ class AmpImaVideo extends AMP.BaseElement {
// Not supported.
}

/** @override */
getMetaData() {
return {
'artwork': [],
'title': '',
'artist': '',
'album': '',
};
}

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

/** @override */
getCurrentTime() {
// Not supported.
Expand Down
15 changes: 15 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 @@ -241,6 +241,21 @@ class AmpNexxtvPlayer extends AMP.BaseElement {
hideControls() {
}

/** @override */
getMetaData() {
return {
'artwork': [],
'title': '',
'artist': '',
'album': '',
};
}

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

/** @override */
getCurrentTime() {
// Not supported.
Expand Down
15 changes: 15 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 @@ -226,6 +226,21 @@ class AmpOoyalaPlayer extends AMP.BaseElement {
hideControls() {
}

/** @override */
getMetaData() {
return {
'artwork': [],
'title': '',
'artist': '',
'album': '',
};
}

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

/** @override */
getCurrentTime() {
// Not supported.
Expand Down
129 changes: 72 additions & 57 deletions extensions/amp-video/0.1/amp-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,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 @@ -73,10 +73,10 @@ class AmpVideo extends AMP.BaseElement {
}
}

/**
* @private
* @return {string}
*/
/**
* @private
* @return {string}
*/
getVideoSource_() {
let videoSrc = this.element.getAttribute('src');
if (!videoSrc) {
Expand All @@ -88,12 +88,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 @@ -103,10 +103,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 @@ -118,7 +118,7 @@ class AmpVideo extends AMP.BaseElement {
Services.videoManagerForDoc(this.element).register(this);
}

/** @override */
/** @override */
mutatedAttributesCallback(mutations) {
if (!this.video_) {
return;
Expand All @@ -137,12 +137,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 @@ -159,7 +159,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 @@ -170,15 +170,15 @@ 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);
});
}

/**
* @private
*/
/**
* @private
*/
installEventHandlers_() {
const video = dev().assertElement(this.video_);
this.forwardEvents([VideoEvents.PLAYING, VideoEvents.PAUSE], video);
Expand All @@ -194,86 +194,101 @@ class AmpVideo extends AMP.BaseElement {
});
}

/** @override */
/** @override */
pauseCallback() {
if (this.video_) {
this.video_.pause();
}
}

/** @private */
/** @private */
isVideoSupported_() {
return !!this.video_.play;
}

// VideoInterface Implementation. See ../src/video-interface.VideoInterface
// VideoInterface Implementation. See ../src/video-interface.VideoInterface

/**
* @override
*/
/**
* @override
*/
supportsPlatform() {
return this.isVideoSupported_();
}

/**
* @override
*/
/**
* @override
*/
isInteractive() {
return this.element.hasAttribute('controls');
}

/**
* @override
*/
/**
* @override
*/
play(unusedIsAutoplay) {
const ret = this.video_.play();

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.
});
}
}

/**
* @override
*/
/**
* @override
*/
pause() {
this.video_.pause();
}

/**
* @override
*/
/**
* @override
*/
mute() {
this.video_.muted = true;
}

/**
* @override
*/
/**
* @override
*/
unmute() {
this.video_.muted = false;
}

/**
* @override
*/
/**
* @override
*/
showControls() {
this.video_.controls = true;
}

/**
* @override
*/
/**
* @override
*/
hideControls() {
this.video_.controls = false;
}

/** @override */
getMetaData() {
return {
'artwork': [],
'title': '',
'artist': '',
'album': '',
};
}

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

/** @override */
getCurrentTime() {
return this.video_.currentTime;
Expand Down
Loading

0 comments on commit dbadc6b

Please sign in to comment.