mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 23:51:20 -08:00
url支持返回promise
This commit is contained in:
1 parent
8ffa4174ae
commit
7cdf6ce904
8 files changed
+60
-62
No files matched your search
@@ -13,19 +13,30 @@ export default function attachUrlMix(art, player) {
|
||||
|
||||
Object.defineProperty(player, 'attachUrl', {
|
||||
value: url => {
|
||||
const typeName = type || getExt(url);
|
||||
const typeCallback = customType[typeName];
|
||||
return sleep().then(() => {
|
||||
if (typeName && typeCallback) {
|
||||
art.emit('beforeCustomType', typeName);
|
||||
typeCallback($video, player.returnUrl(url), art);
|
||||
art.emit('afterCustomType', typeName);
|
||||
} else {
|
||||
art.emit('beforeAttachUrl', url);
|
||||
$video.src = player.returnUrl(url);
|
||||
art.emit('afterAttachUrl', $video.src);
|
||||
}
|
||||
});
|
||||
function attachUrl(videoUrl) {
|
||||
const typeName = type || getExt(videoUrl);
|
||||
const typeCallback = customType[typeName];
|
||||
return sleep().then(() => {
|
||||
if (typeName && typeCallback) {
|
||||
art.emit('beforeCustomType', typeName);
|
||||
typeCallback($video, player.returnUrl(videoUrl), art);
|
||||
art.emit('afterCustomType', typeName);
|
||||
} else {
|
||||
art.emit('beforeAttachUrl', videoUrl);
|
||||
$video.src = player.returnUrl(videoUrl);
|
||||
art.emit('afterAttachUrl', $video.src);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof url === 'function') {
|
||||
return url().then(videoUrl => {
|
||||
art.loading.show();
|
||||
return attachUrl(videoUrl);
|
||||
});
|
||||
}
|
||||
|
||||
return attachUrl(url);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import validElement from './validElement';
|
||||
import validStringEmpty from './validStringEmpty';
|
||||
|
||||
export default {
|
||||
container: {
|
||||
@@ -7,9 +6,8 @@ export default {
|
||||
required: true,
|
||||
},
|
||||
url: {
|
||||
type: 'string',
|
||||
type: 'string|function',
|
||||
required: true,
|
||||
validator: validStringEmpty,
|
||||
},
|
||||
poster: 'string',
|
||||
title: 'string',
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import { ArtPlayerError } from '../utils';
|
||||
|
||||
export default function validStringEmpty(paths, value, type) {
|
||||
if (type !== 'string') {
|
||||
throw new ArtPlayerError(`${paths.join('.')} required 'string' type.`);
|
||||
}
|
||||
|
||||
if (value.trim() === '') {
|
||||
throw new ArtPlayerError(`${paths.join('.')} can not be empty`);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user