YouTube volume fix
This commit is contained in:
parent
4d417d0396
commit
60084a17f8
2
dist/plyr.css
vendored
2
dist/plyr.css
vendored
File diff suppressed because one or more lines are too long
2
dist/plyr.js
vendored
2
dist/plyr.js
vendored
File diff suppressed because one or more lines are too long
2
dist/plyr.js.map
vendored
2
dist/plyr.js.map
vendored
File diff suppressed because one or more lines are too long
@ -253,7 +253,7 @@ const listeners = {
|
|||||||
case 77:
|
case 77:
|
||||||
// M key
|
// M key
|
||||||
if (!held) {
|
if (!held) {
|
||||||
this.toggleMute();
|
this.muted = 'toggle';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -402,7 +402,7 @@ const listeners = {
|
|||||||
// Mute
|
// Mute
|
||||||
utils.on(this.elements.buttons.mute, 'click', event =>
|
utils.on(this.elements.buttons.mute, 'click', event =>
|
||||||
proxy(event, 'mute', () => {
|
proxy(event, 'mute', () => {
|
||||||
this.toggleMute();
|
this.muted = 'toggle';
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -423,7 +423,7 @@ const listeners = {
|
|||||||
// Picture-in-Picture
|
// Picture-in-Picture
|
||||||
utils.on(this.elements.buttons.pip, 'click', event =>
|
utils.on(this.elements.buttons.pip, 'click', event =>
|
||||||
proxy(event, 'pip', () => {
|
proxy(event, 'pip', () => {
|
||||||
this.togglePictureInPicture();
|
this.pip = 'toggle';
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -126,22 +126,28 @@ const vimeo = {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Muted
|
||||||
|
Object.defineProperty(player.media, 'muted', {
|
||||||
|
get() {
|
||||||
|
return volume === 0;
|
||||||
|
},
|
||||||
|
set(input) {
|
||||||
|
const toggle = utils.is.boolean(input) ? input : false;
|
||||||
|
player.volume = toggle ? 0 : player.config.volume;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Source
|
// Source
|
||||||
let currentSrc;
|
let currentSrc;
|
||||||
|
|
||||||
player.embed.getVideoUrl().then(value => {
|
player.embed.getVideoUrl().then(value => {
|
||||||
currentSrc = value;
|
currentSrc = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.defineProperty(player.media, 'currentSrc', {
|
Object.defineProperty(player.media, 'currentSrc', {
|
||||||
get() {
|
get() {
|
||||||
return currentSrc;
|
return currentSrc;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Rebuild UI
|
|
||||||
window.setTimeout(() => ui.build.call(player), 0);
|
|
||||||
|
|
||||||
// Get title
|
// Get title
|
||||||
player.embed.getVideoTitle().then(title => {
|
player.embed.getVideoTitle().then(title => {
|
||||||
player.config.title = title;
|
player.config.title = title;
|
||||||
@ -222,6 +228,9 @@ const vimeo = {
|
|||||||
this.media.paused = true;
|
this.media.paused = true;
|
||||||
utils.dispatchEvent.call(this, this.media, 'ended');
|
utils.dispatchEvent.call(this, this.media, 'ended');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Rebuild UI
|
||||||
|
window.setTimeout(() => ui.build.call(player), 0);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -145,12 +145,26 @@ const youtube = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Volume
|
// Volume
|
||||||
|
let volume = instance.getVolume() / 100;
|
||||||
Object.defineProperty(player.media, 'volume', {
|
Object.defineProperty(player.media, 'volume', {
|
||||||
get() {
|
get() {
|
||||||
return instance.getVolume() / 100;
|
return volume;
|
||||||
},
|
},
|
||||||
set(input) {
|
set(input) {
|
||||||
instance.setVolume(input * 100);
|
volume = input;
|
||||||
|
instance.setVolume(volume * 100);
|
||||||
|
utils.dispatchEvent.call(player, player.media, 'volumechange');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Muted
|
||||||
|
Object.defineProperty(player.media, 'muted', {
|
||||||
|
get() {
|
||||||
|
return instance.isMuted();
|
||||||
|
},
|
||||||
|
set(input) {
|
||||||
|
const toggle = utils.is.boolean(input) ? input : false;
|
||||||
|
instance[toggle ? 'mute' : 'unMute']();
|
||||||
utils.dispatchEvent.call(player, player.media, 'volumechange');
|
utils.dispatchEvent.call(player, player.media, 'volumechange');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -175,9 +189,6 @@ const youtube = {
|
|||||||
player.media.setAttribute('tabindex', -1);
|
player.media.setAttribute('tabindex', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rebuild UI
|
|
||||||
window.setTimeout(() => ui.build.call(player), 0);
|
|
||||||
|
|
||||||
utils.dispatchEvent.call(player, player.media, 'timeupdate');
|
utils.dispatchEvent.call(player, player.media, 'timeupdate');
|
||||||
utils.dispatchEvent.call(player, player.media, 'durationchange');
|
utils.dispatchEvent.call(player, player.media, 'durationchange');
|
||||||
|
|
||||||
@ -205,6 +216,9 @@ const youtube = {
|
|||||||
utils.dispatchEvent.call(player, player.media, 'canplaythrough');
|
utils.dispatchEvent.call(player, player.media, 'canplaythrough');
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
|
// Rebuild UI
|
||||||
|
window.setTimeout(() => ui.build.call(player), 50);
|
||||||
},
|
},
|
||||||
onStateChange(event) {
|
onStateChange(event) {
|
||||||
// Get the instance
|
// Get the instance
|
||||||
|
@ -347,7 +347,6 @@ class Plyr {
|
|||||||
let volume = value;
|
let volume = value;
|
||||||
const max = 1;
|
const max = 1;
|
||||||
const min = 0;
|
const min = 0;
|
||||||
const isSet = !utils.is.undefined(volume);
|
|
||||||
|
|
||||||
if (utils.is.string(volume)) {
|
if (utils.is.string(volume)) {
|
||||||
volume = Number(volume);
|
volume = Number(volume);
|
||||||
@ -377,12 +376,8 @@ class Plyr {
|
|||||||
|
|
||||||
// Toggle muted state
|
// Toggle muted state
|
||||||
if (volume === 0) {
|
if (volume === 0) {
|
||||||
this.toggleMute(true);
|
this.muted = true;
|
||||||
} else if (this.media.muted && isSet) {
|
|
||||||
this.toggleMute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get volume() {
|
get volume() {
|
||||||
@ -404,7 +399,7 @@ class Plyr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Toggle mute
|
// Toggle mute
|
||||||
toggleMute(mute) {
|
set muted(mute) {
|
||||||
// If the method is called without parameter, toggle based on current value
|
// If the method is called without parameter, toggle based on current value
|
||||||
const toggle = utils.is.boolean(mute) ? mute : !this.media.muted;
|
const toggle = utils.is.boolean(mute) ? mute : !this.media.muted;
|
||||||
|
|
||||||
@ -413,32 +408,10 @@ class Plyr {
|
|||||||
|
|
||||||
// Set mute on the player
|
// Set mute on the player
|
||||||
this.media.muted = toggle;
|
this.media.muted = toggle;
|
||||||
|
}
|
||||||
|
|
||||||
// If volume is 0 after unmuting, restore default volume
|
get muted() {
|
||||||
if (!this.media.muted && this.media.volume === 0) {
|
return this.media.muted;
|
||||||
this.setVolume(this.config.volume);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Embeds
|
|
||||||
if (this.isEmbed) {
|
|
||||||
switch (this.type) {
|
|
||||||
case 'youtube':
|
|
||||||
this.embed[this.media.muted ? 'mute' : 'unMute']();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'vimeo':
|
|
||||||
this.embed.setVolume(this.media.muted ? 0 : this.config.volume);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger volumechange for embeds
|
|
||||||
utils.dispatchEvent.call(this, this.media, 'volumechange');
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Playback speed
|
// Playback speed
|
||||||
@ -625,11 +598,9 @@ class Plyr {
|
|||||||
|
|
||||||
// Caption language
|
// Caption language
|
||||||
set language(input) {
|
set language(input) {
|
||||||
const player = this;
|
|
||||||
|
|
||||||
// Nothing specified
|
// Nothing specified
|
||||||
if (!utils.is.string(input)) {
|
if (!utils.is.string(input)) {
|
||||||
return player;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize
|
// Normalize
|
||||||
@ -637,7 +608,7 @@ class Plyr {
|
|||||||
|
|
||||||
// If nothing to change, bail
|
// If nothing to change, bail
|
||||||
if (this.captions.language === language) {
|
if (this.captions.language === language) {
|
||||||
return player;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset UI
|
// Reset UI
|
||||||
@ -654,9 +625,6 @@ class Plyr {
|
|||||||
|
|
||||||
// Re-run setup
|
// Re-run setup
|
||||||
captions.setup.call(this);
|
captions.setup.call(this);
|
||||||
|
|
||||||
// Allow chaining
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get language() {
|
get language() {
|
||||||
@ -725,8 +693,7 @@ class Plyr {
|
|||||||
// Toggle picture-in-picture
|
// Toggle picture-in-picture
|
||||||
// TODO: update player with state, support, enabled
|
// TODO: update player with state, support, enabled
|
||||||
// TODO: detect outside changes
|
// TODO: detect outside changes
|
||||||
togglePictureInPicture(input) {
|
set pip(input) {
|
||||||
const player = this;
|
|
||||||
const states = {
|
const states = {
|
||||||
pip: 'picture-in-picture',
|
pip: 'picture-in-picture',
|
||||||
inline: 'inline',
|
inline: 'inline',
|
||||||
@ -734,21 +701,27 @@ class Plyr {
|
|||||||
|
|
||||||
// Bail if no support
|
// Bail if no support
|
||||||
if (!support.pip) {
|
if (!support.pip) {
|
||||||
return player;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle based on current state if not passed
|
// Toggle based on current state if not passed
|
||||||
const toggle = utils.is.boolean(input) ? input : this.media.webkitPresentationMode === states.inline;
|
const toggle = utils.is.boolean(input) ? input : this.pip === states.inline;
|
||||||
|
|
||||||
// Toggle based on current state
|
// Toggle based on current state
|
||||||
this.media.webkitSetPresentationMode(toggle ? states.pip : states.inline);
|
this.media.webkitSetPresentationMode(toggle ? states.pip : states.inline);
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
get pip() {
|
||||||
|
if (!support.pip) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.media.webkitPresentationMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger airplay
|
// Trigger airplay
|
||||||
// TODO: update player with state, support, enabled
|
// TODO: update player with state, support, enabled
|
||||||
airPlay() {
|
airplay() {
|
||||||
// Bail if no support
|
// Bail if no support
|
||||||
if (!support.airplay) {
|
if (!support.airplay) {
|
||||||
return this;
|
return this;
|
||||||
|
12
src/js/ui.js
12
src/js/ui.js
@ -7,7 +7,6 @@ import captions from './captions';
|
|||||||
import controls from './controls';
|
import controls from './controls';
|
||||||
import fullscreen from './fullscreen';
|
import fullscreen from './fullscreen';
|
||||||
import listeners from './listeners';
|
import listeners from './listeners';
|
||||||
import storage from './storage';
|
|
||||||
|
|
||||||
const ui = {
|
const ui = {
|
||||||
addStyleHook() {
|
addStyleHook() {
|
||||||
@ -72,7 +71,6 @@ const ui = {
|
|||||||
|
|
||||||
// Set volume
|
// Set volume
|
||||||
this.volume = null;
|
this.volume = null;
|
||||||
ui.updateVolume.call(this);
|
|
||||||
|
|
||||||
// Set playback speed
|
// Set playback speed
|
||||||
this.speed = null;
|
this.speed = null;
|
||||||
@ -169,19 +167,19 @@ const ui = {
|
|||||||
updateVolume() {
|
updateVolume() {
|
||||||
// Update the <input type="range"> if present
|
// Update the <input type="range"> if present
|
||||||
if (this.supported.ui) {
|
if (this.supported.ui) {
|
||||||
const value = this.media.muted ? 0 : this.media.volume;
|
const value = this.muted ? 0 : this.volume;
|
||||||
|
|
||||||
if (this.elements.inputs.volume) {
|
if (utils.is.htmlElement(this.elements.inputs.volume)) {
|
||||||
ui.setRange.call(this, this.elements.inputs.volume, value);
|
ui.setRange.call(this, this.elements.inputs.volume, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle class if muted
|
// Toggle class if muted
|
||||||
utils.toggleClass(this.elements.container, this.config.classNames.muted, this.media.muted);
|
utils.toggleClass(this.elements.container, this.config.classNames.muted, this.muted);
|
||||||
|
|
||||||
// Update checkbox for mute state
|
// Update checkbox for mute state
|
||||||
if (this.supported.ui && this.elements.buttons.mute) {
|
if (this.supported.ui && utils.is.htmlElement(this.elements.buttons.mute)) {
|
||||||
utils.toggleState(this.elements.buttons.mute, this.media.muted);
|
utils.toggleState(this.elements.buttons.mute, this.muted);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
right: 0;
|
right: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
padding: (@plyr-control-spacing * 3.5) (@plyr-control-spacing + 2) @plyr-control-spacing;
|
padding: (@plyr-control-spacing * 3.5) @plyr-control-spacing @plyr-control-spacing;
|
||||||
background: linear-gradient(fade(@plyr-video-controls-bg, 0%), fade(@plyr-video-controls-bg, 70%));
|
background: linear-gradient(fade(@plyr-video-controls-bg, 0%), fade(@plyr-video-controls-bg, 70%));
|
||||||
border-bottom-left-radius: inherit;
|
border-bottom-left-radius: inherit;
|
||||||
border-bottom-right-radius: inherit;
|
border-bottom-right-radius: inherit;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user