├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── demo ├── demo-elements.js └── index.html ├── google-youtube.js ├── index.html ├── package-lock.json ├── package.json └── test ├── google-youtube-basic.html ├── google-youtube-custom-thumbnail.html └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Google Inc 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | https://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | google-youtube 2 | ============== 3 | 4 | See https://elements.polymer-project.org/elements/google-youtube 5 | 6 | Test 7 | ==== 8 | 9 | ``` 10 | polymer test --module-resolution=node --npm 11 | ``` -------------------------------------------------------------------------------- /demo/demo-elements.js: -------------------------------------------------------------------------------- 1 | import '@polymer/polymer/polymer-legacy.js'; 2 | import '../google-youtube.js'; 3 | import { Polymer } from '@polymer/polymer/lib/legacy/polymer-fn.js'; 4 | const $_documentContainer = document.createElement('template'); 5 | 6 | $_documentContainer.innerHTML = ` 7 | 91 | 92 | `; 93 | 94 | document.head.appendChild($_documentContainer.content); 95 | Polymer({ 96 | is: 'demo-element', 97 | properties: { 98 | playSupported: Boolean, 99 | state: Number, 100 | currentTime: Number, 101 | currentTimeFormatted: String, 102 | duration: Number, 103 | durationFormatted: String, 104 | fractionLoaded: Number, 105 | volume: Number, 106 | playbackRate: Number, 107 | playbackQuality: String, 108 | events: { 109 | type: Array, 110 | value: [] 111 | } 112 | }, 113 | computeProgress: function(currentTime, duration) { 114 | if (currentTime === undefined || duration === undefined) { 115 | return 0; 116 | } 117 | 118 | return currentTime / duration; 119 | }, 120 | computePlayDisabled: function(state, playSupported) { 121 | return state == 1 || state == 3 || !playSupported; 122 | }, 123 | computePauseDisabled: function(state) { 124 | return state != 1 && state != 3; 125 | }, 126 | handleStateChange: function(ev) { 127 | this.events.push({data: ev.detail.data}); 128 | }, 129 | handleYouTubeError: function(ev) { 130 | console.error('YouTube playback error', ev.detail); 131 | }, 132 | handlePlayVideo: function(ev) { 133 | this.$.googleYouTube.play(); 134 | }, 135 | handlePauseVideo: function(ev) { 136 | this.$.googleYouTube.pause(); 137 | }, 138 | handleCueVideo: function(ev) { 139 | this.$.googleYouTube.videoId = this.$.videoId.value; 140 | } 141 | }); 142 | -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <google-youtube> Demo 8 | 9 | 10 | 11 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /google-youtube.js: -------------------------------------------------------------------------------- 1 | /** 2 | @license 3 | Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 4 | This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt 5 | The complete set of authors may be found at https://polymer.github.io/AUTHORS.txt 6 | The complete set of contributors may be found at https://polymer.github.io/CONTRIBUTORS.txt 7 | Code distributed by Google as part of the polymer project is also 8 | subject to an additional IP rights grant found at https://polymer.github.io/PATENTS.txt 9 | */ 10 | import '@google-web-components/google-apis/google-youtube-api.js'; 11 | import '@polymer/iron-localstorage/iron-localstorage.js'; 12 | 13 | import { Polymer } from '@polymer/polymer/lib/legacy/polymer-fn.js'; 14 | import { html } from '@polymer/polymer/lib/utils/html-tag.js'; 15 | 16 | /** 17 | `google-youtube` encapsulates the YouTube player into a web component. 18 | 19 | 26 | 27 | 28 | `google-youtube` supports all of the [embedded player parameters](https://developers.google.com/youtube/player_parameters). Each can be set as an attribute on `google-youtube`. 29 | 30 | The standard set of [YouTube player events](https://developers.google.com/youtube/iframe_api_reference#Events) are exposed, as well as methods for playing, pausing, seeking to a specific time, and loading a new video. 31 | 32 | 33 | Custom property | Description | Default 34 | ----------------|-------------|---------- 35 | `--google-youtube-container` | Mixin applied to the container div | `{}` 36 | `--google-youtube-thumbnail` | Mixin for the video thumbnail | `{}` 37 | `--google-youtube-iframe` | Mixin for the embeded iframe | `{}` 38 | 39 | 40 | @demo 41 | */ 42 | Polymer({ 43 | _template: html` 44 | 82 |
83 | 86 | 87 | 92 | 93 | 95 | 96 | 97 | 98 |
99 |
100 | `, 101 | 102 | is: 'google-youtube', 103 | 104 | /** 105 | * Fired when the YouTube player is fully initialized and ready for use. 106 | * 107 | * @event google-youtube-ready 108 | */ 109 | 110 | /** 111 | * Fired when the state of the player changes. `e.detail.data` is set to one of 112 | * [the documented](https://developers.google.com/youtube/iframe_api_reference#onStateChange) 113 | * states. 114 | * 115 | * @event google-youtube-state-change 116 | */ 117 | 118 | /** 119 | * Fired when playback fails due to an error. `e.detail.data` is set to one of 120 | * [the documented](https://developers.google.com/youtube/iframe_api_reference#onError) 121 | * error codes. 122 | * 123 | * @event google-youtube-error 124 | */ 125 | 126 | properties: { 127 | /** 128 | * Sets the id of the video to play. Changing this attribute will trigger a call 129 | * to load a new video into the player (if `this.autoplay` is set to `1` and `playsupported` is true) 130 | * or cue a new video otherwise. 131 | * 132 | * The underlying YouTube embed will not be added to the page unless 133 | * `videoId` or `list` property is set. 134 | * 135 | * You can [search for videos programmatically](https://developers.google.com/youtube/v3/docs/search/list) 136 | * using the YouTube Data API, or just hardcode known video ids to display on your page. 137 | */ 138 | videoId: { 139 | type: String, 140 | value: '', 141 | observer: '_videoIdChanged' 142 | }, 143 | 144 | /** 145 | * The list parameter, in conjunction with the listType parameter, identifies the content that will load in the player. 146 | * If the listType parameter value is search, then the list parameter value specifies the search query. 147 | * If the listType parameter value is user_uploads, then the list parameter value identifies the YouTube channel whose uploaded videos will be loaded. 148 | * If the listType parameter value is playlist, then the list parameter value specifies a YouTube playlist ID. In the parameter value, you need to prepend the playlist ID with the letters PL as shown in the example below. 149 | * 150 | * See https://developers.google.com/youtube/player_parameters#list 151 | */ 152 | list: { 153 | type: String, 154 | value: '' 155 | }, 156 | 157 | /** 158 | * See https://developers.google.com/youtube/player_parameters#listtype 159 | */ 160 | listType: String, 161 | 162 | /** 163 | * Decides whether YouTube API should be loaded. 164 | */ 165 | shouldLoadApi: { 166 | type: Boolean, 167 | computed: '_computeShouldLoadApi(list, videoId)' 168 | }, 169 | 170 | /** 171 | * Whether programmatic `