From 3cf279b83cf73f6a967372f9acc9f8db4c65520b Mon Sep 17 00:00:00 2001 From: Vladimir Kirilyuk Date: Thu, 10 May 2018 23:00:36 -0700 Subject: [PATCH 1/2] Added statsUpdateInterval parameter to control stats update frequency --- google-youtube.html | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/google-youtube.html b/google-youtube.html index 7c7062e..863d7b5 100755 --- a/google-youtube.html +++ b/google-youtube.html @@ -387,7 +387,17 @@ type: String, value: '', notify: true - } + }, + + /** + * Sets refresh interval in milliseconds for updating playback stats. + * YouTube API does not send events for video progress so we have to + * call getCurrentTime() manually. Smaller value makes updates smoother. + */ + statsUpdateInterval: { + type: Number, + value: 1000, + }, }, @@ -744,7 +754,7 @@ this.durationformatted = this._toHHMMSS(this.duration); if (!this.__updatePlaybackStatsInterval) { - this.__updatePlaybackStatsInterval = setInterval(this._updatePlaybackStats.bind(this), 1000); + this.__updatePlaybackStatsInterval = setInterval(this._updatePlaybackStats.bind(this), this.statsUpdateInterval); } } else { // We only need to update the stats if the video is playing. @@ -773,7 +783,7 @@ }, _updatePlaybackStats: function() { - this.currenttime = Math.round(this._player.getCurrentTime()); + this.currenttime = this._player.getCurrentTime(); this.currenttimeformatted = this._toHHMMSS(this.currenttime); this.fractionloaded = this._player.getVideoLoadedFraction(); this.volume = this._player.getVolume(); @@ -808,4 +818,3 @@ }); - From 972413b4f5fddf72d6bfb55107ca85cb080fee06 Mon Sep 17 00:00:00 2001 From: Vladimir Kirilyuk Date: Thu, 10 May 2018 23:23:14 -0700 Subject: [PATCH 2/2] Add TypeScript definitions for --- google-youtube.d.ts | 381 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 381 insertions(+) create mode 100644 google-youtube.d.ts diff --git a/google-youtube.d.ts b/google-youtube.d.ts new file mode 100644 index 0000000..5971a8a --- /dev/null +++ b/google-youtube.d.ts @@ -0,0 +1,381 @@ +/** + * DO NOT EDIT + * + * This file was automatically generated by + * https://github.com/Polymer/gen-typescript-declarations + * + * To modify these typings, edit the source file(s): + * google-youtube.html + */ + +/// +/// +/// + +/** + * `google-youtube` encapsulates the YouTube player into a web component. + * + * + * + * + * `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`. + * + * 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. + * + * + * Custom property | Description | Default + * ----------------|-------------|---------- + * `--google-youtube-container` | Mixin applied to the container div | `{}` + * `--google-youtube-thumbnail` | Mixin for the video thumbnail | `{}` + * `--google-youtube-iframe` | Mixin for the embeded iframe | `{}` + */ +interface GoogleYoutubeElement extends Polymer.Element { + + /** + * Sets the id of the video to play. Changing this attribute will trigger a call + * to load a new video into the player (if `this.autoplay` is set to `1` and `playsupported` is true) + * or cue a new video otherwise. + * + * The underlying YouTube embed will not be added to the page unless + * `videoId` or `list` property is set. + * + * You can [search for videos programmatically](https://developers.google.com/youtube/v3/docs/search/list) + * using the YouTube Data API, or just hardcode known video ids to display on your page. + */ + videoId: string|null|undefined; + + /** + * The list parameter, in conjunction with the listType parameter, identifies the content that will load in the player. + * If the listType parameter value is search, then the list parameter value specifies the search query. + * If the listType parameter value is user_uploads, then the list parameter value identifies the YouTube channel whose uploaded videos will be loaded. + * 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. + * + * See https://developers.google.com/youtube/player_parameters#list + */ + list: string|null|undefined; + + /** + * See https://developers.google.com/youtube/player_parameters#listtype + */ + listType: string|null|undefined; + + /** + * Decides whether YouTube API should be loaded. + */ + readonly shouldLoadApi: boolean|null|undefined; + + /** + * Whether programmatic `