forked from ampproject/amphtml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
364 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
85
extensions/amp-brid-player/0.1/test/test-amp-brid-player.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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><script async custom-element="amp-brid-player" src="https://cdn.ampproject.org/v0/amp-brid-player-0.1.js"></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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.