mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-14 00:06:17 -08:00
32 lines
890 B
JavaScript
32 lines
890 B
JavaScript
import { clamp } from '../utils';
|
|
|
|
export default function volumeMix(art, player) {
|
|
const {
|
|
refs: { $video },
|
|
i18n,
|
|
notice,
|
|
storage,
|
|
} = art;
|
|
|
|
Object.defineProperty(player, 'volume', {
|
|
get: () => $video.volume || 0,
|
|
set: percentage => {
|
|
if (percentage !== undefined) {
|
|
$video.volume = clamp(percentage, 0, 1);
|
|
notice.show(`${i18n.get('Volume')}: ${parseInt($video.volume * 100, 10)}`);
|
|
if ($video.volume !== 0) {
|
|
storage.set('volume', $video.volume);
|
|
}
|
|
art.emit('volumeChange', $video.volume);
|
|
}
|
|
},
|
|
});
|
|
|
|
Object.defineProperty(player, 'mute', {
|
|
get: () => player.volume === 0,
|
|
set: mute => {
|
|
player.volume = mute ? 0 : storage.get('volume');
|
|
},
|
|
});
|
|
}
|