Skip to content

Commit

Permalink
Adding amp-brid-player component
Browse files Browse the repository at this point in the history
  • Loading branch information
DarXector committed Mar 15, 2016
1 parent 9d5ad62 commit 18c9960
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 0 deletions.
25 changes: 25 additions & 0 deletions examples/brid-player.amp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html >
<head>
<meta charset="utf-8">
<title>Brid.tv Player Example</title>
<link rel="canonical" href="amps.html" >
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Georgia|Open+Sans|Roboto' rel='stylesheet' type='text/css'>
<script async custom-element="amp-brid-player" src="https://cdn.ampproject.org/v0/amp-brid-player-0.1.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
<h2>Brid Player</h2>

<amp-brid-player
data-partner="264"
data-player="4144"
data-video="13663"
layout="responsive"
width="480" height="270">
</amp-brid-player>

</body>
</html>
1 change: 1 addition & 0 deletions extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Current list of extended components:
| [`amp-analytics`](amp-analytics/amp-analytics.md) | Captures analytics data from an AMP document. |
| [`amp-anim`](amp-anim/amp-anim.md) | Manages an animated image, typically a GIF. |
| [`amp-audio`](amp-audio/amp-audio.md) | Replaces the HTML5 `audio` tag. |
| [`amp-brid-player`](amp-brid-player/amp-brid-player.md) | Displays a Brid.tv player. |
| [`amp-brightcove`](amp-brightcove/amp-brightcove.md) | Displays a Brightcove Video Cloud or Perform player. |
| [`amp-carousel`](amp-carousel/amp-carousel.md) | Displays multiple similar pieces of content along a horizontal axis. |
| [`amp-dailymotion`](amp-dailymotion/amp-dailymotion.md) | Displays a [Dailymotion](https://www.dailymotion.com) video. |
Expand Down
139 changes: 139 additions & 0 deletions extensions/amp-brid-player/0.1/amp-brid-player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* Copyright 2015 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {getLengthNumeral, isLayoutSizeDefined} from '../../../src/layout';
import {loadPromise} from '../../../src/event-helper';
import {setStyles} from '../../../src/style';

class AmpBridPlayer extends AMP.BaseElement {

/** @override */
preconnectCallback(onLayout) {
this.preconnect.url('https://services.brid.tv', onLayout);
this.preconnect.url('https://cdn.brid.tv', onLayout);
}

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

/** @override */
buildCallback() {
const width = this.element.getAttribute('width');
const height = this.element.getAttribute('height');

/** @private @const {number} */
this.width_ = getLengthNumeral(width);

/** @private @const {number} */
this.height_ = getLengthNumeral(height);

/** @private @const {string} */
this.partnerID_ = AMP.assert(
this.element.getAttribute('data-partner'),
'The data-partner attribute is required for <amp-brid-player> %s',
this.element);

/** @private @const {string} */
this.feedID_ = AMP.assert(
(this.element.getAttribute('data-video') ||
this.element.getAttribute('data-playlist')),
'Either the data-video or the data-playlist ' +
'attributes must be specified for <amp-brid-player> %s',
this.element);

if (!this.getPlaceholder()) {
this.buildImagePlaceholder_();
}
}

/** @override */
layoutCallback() {
const playerID = AMP.assert(this.element.getAttribute('data-player'),
'The data-player attribute is required for <amp-brid-player> %s',
this.element);

const partnerID = AMP.assert(
this.partnerID_,
'The data-partner attribute is required for <amp-brid-player> %s',
this.element);

let feedType;

if (this.element.getAttribute('data-video')) {
feedType = 'video';
} else if (this.element.getAttribute('data-playlist')) {
feedType = 'playlist';
}

//Create iframe
const iframe = document.createElement('iframe');
const src = 'https://services.brid.tv/services/iframe/' + encodeURIComponent(feedType) + '/' + encodeURIComponent(this.feedID_) + '/' + encodeURIComponent(partnerID) + '/' + encodeURIComponent(playerID) + '/0/1';
iframe.setAttribute('frameborder', '0');
iframe.setAttribute('allowfullscreen', 'true');
iframe.src = src;
this.applyFillContent(iframe);
iframe.width = this.width_;
iframe.height = this.height_;
this.element.appendChild(iframe);
/** @private {?Element} */
this.iframe_ = iframe;
return loadPromise(iframe);
}

/** @override */
documentInactiveCallback() {
if (this.iframe_ && this.iframe_.contentWindow) {
this.iframe_.contentWindow./*OK*/postMessage(
'Brid|pause', 'https://services.brid.tv');
}
return false;
}

/** @private */
buildImagePlaceholder_() {
const imgPlaceholder = new Image();
const partnerID = this.partnerID_;
const feedID = this.feedID_;

setStyles(imgPlaceholder, {
'object-fit': 'cover',
// Hiding the placeholder initially to give the browser time to fix
// the object-fit: cover.
'visibility': 'hidden',
});

imgPlaceholder.src = 'https://cdn.brid.tv/live/partners/' + encodeURIComponent(partnerID) + '/snapshot/' + encodeURIComponent(feedID) + '.jpg';
imgPlaceholder.setAttribute('placeholder', '');
imgPlaceholder.width = this.width_;
imgPlaceholder.height = this.height_;

this.element.appendChild(imgPlaceholder);
this.applyFillContent(imgPlaceholder);

loadPromise(imgPlaceholder).catch(() => {
imgPlaceholder.src = 'https://services.brid.tv/ugc/default/defaultSnapshot.png';
return loadPromise(imgPlaceholder);
}).then(() => {
setStyles(imgPlaceholder, {
'visibility': '',
});
});
}
};

AMP.registerElement('amp-brid-player', AmpBridPlayer);
85 changes: 85 additions & 0 deletions extensions/amp-brid-player/0.1/test/test-amp-brid-player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright 2015 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {createIframePromise} from '../../../../testing/iframe';
require('../amp-brid-player');
import {adopt} from '../../../../src/runtime';

adopt(window);

describe('amp-brid-player', () => {

function getBridPlayer(attributes, opt_responsive) {
return createIframePromise().then(iframe => {
const bc = iframe.doc.createElement('amp-brid-player');
for (const key in attributes) {
bc.setAttribute(key, attributes[key]);
}
bc.setAttribute('width', '640');
bc.setAttribute('height', '360');
if (opt_responsive) {
bc.setAttribute('layout', 'responsive');
}
iframe.doc.body.appendChild(bc);
bc.implementation_.layoutCallback();
return bc;
});
}

it('renders', () => {
return getBridPlayer({
'data-partner': '264',
'data-player': '4144',
'data-video': '13663',
}).then(bc => {
const iframe = bc.querySelector('iframe');
expect(iframe).to.not.be.null;
expect(iframe.tagName).to.equal('IFRAME');
expect(iframe.src).to.equal(
'https://services.brid.tv/services/iframe/video/13663/264/4144/0/1');
expect(iframe.getAttribute('width')).to.equal('640');
expect(iframe.getAttribute('height')).to.equal('360');
});
});

it('renders responsively', () => {
return getBridPlayer({
'data-partner': '1177',
'data-player': '979',
'data-video': '5204',
}, true).then(bc => {
const iframe = bc.querySelector('iframe');
expect(iframe).to.not.be.null;
expect(iframe.className).to.match(/-amp-fill-content/);
});
});

it('requires data-partner', () => {
return getBridPlayer({
'data-player': '4144',
'data-video': '13663',
}).should.eventually.be.rejectedWith(
/The data-partner attribute is required for/);
});

it('requires data-player', () => {
return getBridPlayer({
'data-partner': '264',
'data-video': '13663',
}).should.eventually.be.rejectedWith(
/The data-player attribute is required for/);
});
});
108 changes: 108 additions & 0 deletions extensions/amp-brid-player/amp-brid-player.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!---
Copyright 2015 The AMP HTML Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# <a name="amp-brid-player"></a> `amp-brid-player`

<table>
<tr>
<td width="40%"><strong>Description</strong></td>
<td>An <code>amp-brid-player</code> displays the Brid Player used in <a href="https://www.brid.tv/">Brid.tv</a> Video Platform.
</tr>
<tr>
<td width="40%"><strong>Availability</strong></td>
<td>Stable</td>
</tr>
<tr>
<td width="40%"><strong>Required Script</strong></td>
<td><code>&lt;script async custom-element="amp-brid-player" src="https://cdn.ampproject.org/v0/amp-brid-player-0.1.js">&lt;/script></code></td>
</tr>
<tr>
<td width="40%"><strong>Examples</strong></td>
<td><a href="https://github.com/ampproject/amphtml/blob/master/examples/brid-player.amp.html">brid-player.amp.html</a></td>
</tr>
</table>

The following lists validation errors specific to the `amp-brid-player` tag
(see also `amp-brid-player` in the [AMP validator specification](https://github.com/ampproject/amphtml/blob/master/validator/validator.protoascii)):

<table>
<tr>
<th width="40%"><strong>Validation Error</strong></th>
<th>Description</th>
</tr>
<tr>
<td width="40%"><a href="https://www.ampproject.org/docs/reference/validation_errors.html#tag-required-by-another-tag-is-missing">TAG_REQUIRED_BY_MISSING</a></td>
<td>Error thrown when required <code>amp-brid-player</code> extension <code>.js</code> script tag is missing or incorrect.</td>
</tr>
<tr>
<td width="40%"><a href="https://www.ampproject.org/docs/reference/validation_errors.html#mandatory-attribute-missing">MANDATORY_ATTR_MISSING</a></td>
<td>Error thrown when <code>data-partner</code> attribute is missing.</td>
</tr>
<tr>
<td width="40%"><a href="https://www.ampproject.org/docs/reference/validation_errors.html#mandatory-attribute-missing">MANDATORY_ATTR_MISSING</a></td>
<td>Error thrown when <code>data-player</code> attribute is missing.</td>
</tr>
<tr>
<td width="40%"><a href="https://www.ampproject.org/docs/reference/validation_errors.html#mandatory-attribute-missing">MANDATORY_ONEOF_ATTR_MISSING</a></td>
<td>Error thrown when either the <code>data-video</code> or <code>data-playlist</code> attributes are missing.</td>
</tr>
<tr>
<td width="40%"><a href="https://www.ampproject.org/docs/reference/validation_errors.html#implied-layout-isnt-supported-by-amp-tag">IMPLIED_LAYOUT_INVALID</a></td>
<td>Error thrown when implied layout is set to <code>CONTAINER</code>; this layout type isn't supported.</td>
</tr>
<tr>
<td width="40%"><a href="https://www.ampproject.org/docs/reference/validation_errors.html#specified-layout-isnt-supported-by-amp-tag">SPECIFIED_LAYOUT_INVALID</a></td>
<td>Error thrown when specified layout is set to <code>CONTAINER</code>; this layout type isn't supported.</td>
</tr>
<tr>
<td width="40%"><a href="https://www.ampproject.org/docs/reference/validation_errors.html#invalid-property-value">INVALID_PROPERTY_VALUE_IN_ATTR_VALUE</a></td>
<td>Error thrown when invalid value is given for attributes <code>height</code> or <code>width</code>. For example, <code>height=auto</code> triggers this error for all supported layout types, with the exception of <code>NODISPLAY</code>.</td>
</tr>
</table>

## Example

The `width` and `height` attributes determine the aspect ratio of the player embedded in responsive layouts.

Examples:

```html
<amp-brid-player
data-partner="264"
data-player="4144"
data-video="13663"
layout="responsive"
width="480" height="270">
</amp-brid-player>
```

## Attributes

**data-partner**

The Brid.tv partner id.

**data-player**

The Brid.tv player id. Specific to every partner.

**data-video**

The Brid.tv video ID.

**data-playlist**

The Brid.tv playlist ID. Embed must either have video or playlist attribute.
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function buildExtensions(options) {
buildExtension('amp-analytics', '0.1', false, options);
buildExtension('amp-anim', '0.1', false, options);
buildExtension('amp-audio', '0.1', false, options);
buildExtension('amp-brid-player', '0.1', false, options);
buildExtension('amp-brightcove', '0.1', false, options);
buildExtension('amp-carousel', '0.1', true, options);
buildExtension('amp-dailymotion', '0.1', false, options);
Expand Down Expand Up @@ -319,6 +320,7 @@ function buildExamples(watch) {
buildExample('analytics-notification.amp.html');
buildExample('analytics.amp.html');
buildExample('article.amp.html');
buildExample('brid-player.amp.html');
buildExample('brightcove.amp.html');
buildExample('responsive.amp.html');
buildExample('article-access.amp.html');
Expand Down
1 change: 1 addition & 0 deletions spec/amp-html-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ In these cases, services may set up endpoints that produce data that conforms to
- [amp-ad](../builtins/amp-ad.md)
- [amp-pixel](../builtins/amp-pixel.md)
- [amp-video](../builtins/amp-video.md)
- [amp-brid-player](../extensions/amp-brid-player/amp-brid-player.md)
- [amp-brightcove](../extensions/amp-brightcove/amp-brightcove.md)
- [amp-carousel](../extensions/amp-carousel/amp-carousel.md)
- [amp-font](../extensions/amp-font/amp-font.md)
Expand Down
Loading

0 comments on commit 18c9960

Please sign in to comment.