Files
ArtPlayer/packages/artplayer/src/player/urlMix.js
T
2022-01-07 17:38:10 +08:00

37 lines
1022 B
JavaScript

import { getExt, def, sleep } from '../utils';
export default function urlMix(art) {
const {
option,
template: { $video },
} = art;
def(art, 'url', {
get() {
return $video.currentSrc;
},
set(url) {
const typeName = option.type || getExt(url);
const typeCallback = option.customType[typeName];
if (typeName && typeCallback) {
sleep().then(() => {
art.loading.show = true;
typeCallback.call(art, $video, url, art);
});
} else {
if (art.url && art.url !== url) {
art.once('video:canplay', () => {
if (art.isReady) {
art.emit('restart');
}
});
}
$video.src = url;
art.option.url = url;
art.emit('url', url);
}
},
});
}