mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-17 10:01:20 -08:00
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
import { def } from '../utils';
|
|
|
|
export default function switchMix(art) {
|
|
const { i18n, option, notice } = art;
|
|
|
|
function switchUrl(url, name, currentTime) {
|
|
return new Promise((resolve) => {
|
|
if (url === art.url) return resolve(url);
|
|
const { playing } = art;
|
|
art.pause();
|
|
URL.revokeObjectURL(art.url);
|
|
art.url = url;
|
|
art.once('video:canplay', () => {
|
|
art.playbackRate = false;
|
|
art.aspectRatio = false;
|
|
art.flip = 'normal';
|
|
art.autoSize = option.autoSize;
|
|
art.currentTime = currentTime;
|
|
art.notice.show = '';
|
|
if (playing) {
|
|
art.play();
|
|
}
|
|
if (name) {
|
|
notice.show = `${i18n.get('Switch Video')}: ${name}`;
|
|
}
|
|
art.emit('switch', url);
|
|
resolve(url);
|
|
});
|
|
});
|
|
}
|
|
|
|
def(art, 'switchQuality', {
|
|
value: (url, name) => {
|
|
return switchUrl(url, name, art.currentTime);
|
|
},
|
|
});
|
|
|
|
def(art, 'switchUrl', {
|
|
value: (url, name) => {
|
|
return switchUrl(url, name, 0);
|
|
},
|
|
});
|
|
}
|