aboutsummaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js')
-rw-r--r--src/js/plugins/vimeo.js22
-rw-r--r--src/js/plugins/youtube.js18
-rw-r--r--src/js/plyr.js59
3 files changed, 38 insertions, 61 deletions
diff --git a/src/js/plugins/vimeo.js b/src/js/plugins/vimeo.js
index 7bcb2d01..8c7f2b04 100644
--- a/src/js/plugins/vimeo.js
+++ b/src/js/plugins/vimeo.js
@@ -77,9 +77,9 @@ const vimeo = {
player.media.paused = true;
player.media.currentTime = 0;
- let { currentTime } = player.media;
// Seeking
+ let { currentTime } = player.media;
Object.defineProperty(player.media, 'currentTime', {
get() {
return currentTime;
@@ -114,14 +114,34 @@ const vimeo = {
set() {},
});
+ // Volume
+ let { volume } = player.media;
+ Object.defineProperty(player.media, 'volume', {
+ get() {
+ return volume;
+ },
+ set(input) {
+ volume = input;
+ player.embed.setVolume(input);
+ utils.dispatchEvent.call(player, player.media, 'volumechange');
+ },
+ });
+
// Rebuild UI
window.setTimeout(() => ui.build.call(player), 0);
+ // Get title
+ player.embed.getVideoTitle().then(title => {
+ player.config.title = title;
+ });
+
+ // Get current time
player.embed.getCurrentTime().then(value => {
currentTime = value;
utils.dispatchEvent.call(this, this.media, 'timeupdate');
});
+ // Get duration
player.embed.getDuration().then(value => {
player.media.duration = value;
utils.dispatchEvent.call(player, player.media, 'durationchange');
diff --git a/src/js/plugins/youtube.js b/src/js/plugins/youtube.js
index ce21433e..7b8447c2 100644
--- a/src/js/plugins/youtube.js
+++ b/src/js/plugins/youtube.js
@@ -140,8 +140,19 @@ const youtube = {
get() {
return instance.getPlaybackRate();
},
- set(speed) {
- instance.setPlaybackRate(speed);
+ set(input) {
+ instance.setPlaybackRate(input);
+ },
+ });
+
+ // Volume
+ Object.defineProperty(player.media, 'volume', {
+ get() {
+ return instance.getVolume() / 100;
+ },
+ set(input) {
+ instance.setVolume(input * 100);
+ utils.dispatchEvent.call(player, player.media, 'volumechange');
},
});
@@ -235,9 +246,8 @@ const youtube = {
// Poll to get playback progress
player.timers.playing = window.setInterval(() => {
- // player.media.currentTime = instance.getCurrentTime();
utils.dispatchEvent.call(player, player.media, 'timeupdate');
- }, 100);
+ }, 50);
// Check duration again due to YouTube bug
// https://github.com/sampotts/plyr/issues/374
diff --git a/src/js/plyr.js b/src/js/plyr.js
index 60960d01..cc997094 100644
--- a/src/js/plyr.js
+++ b/src/js/plyr.js
@@ -320,40 +320,7 @@ class Plyr {
targetTime = this.duration;
}
- // Set the current time
- // TODO: This should be included in the "adapters"
- // Embeds
- /* if (this.isEmbed) {
- // Get current paused state
- const { paused } = this.media;
-
- switch (this.type) {
- case 'youtube':
- this.embed.seekTo(targetTime);
- break;
-
- case 'vimeo':
- this.embed.setCurrentTime(targetTime);
- break;
-
- default:
- break;
- }
-
- // Restore pause (some will play on seek)
- if (paused) {
- this.pause();
- }
-
- // Set seeking flag
- this.media.seeking = true;
-
- // Trigger seeking
- utils.dispatchEvent.call(this, this.media, 'seeking');
- } else {
-
- } */
-
+ // Set
this.media.currentTime = targetTime.toFixed(4);
// Logging
@@ -364,7 +331,7 @@ class Plyr {
return Number(this.media.currentTime);
}
- // Get the duration (or custom if set)
+ // Duration
get duration() {
// Faux duration set via config
const fauxDuration = parseInt(this.config.duration, 10);
@@ -376,7 +343,7 @@ class Plyr {
return !Number.isNaN(fauxDuration) ? fauxDuration : realDuration;
}
- // Set volume
+ // Volume
set volume(value) {
let volume = value;
const max = 1;
@@ -409,26 +376,6 @@ class Plyr {
// Set the player volume
this.media.volume = volume;
- // Trigger volumechange for embeds
- // TODO: Do in adapters
- if (this.isEmbed) {
- // Set media volume
- switch (this.type) {
- case 'youtube':
- this.embed.setVolume(this.media.volume * 100);
- break;
-
- case 'vimeo':
- this.embed.setVolume(this.media.volume);
- break;
-
- default:
- break;
- }
-
- utils.dispatchEvent.call(this, this.media, 'volumechange');
- }
-
// Toggle muted state
if (volume === 0) {
this.toggleMute(true);