mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 05:41:20 -08:00
add ts
This commit is contained in:
1 parent
965e3e008f
commit
95bbe6f3b2
8 files changed
+57
-98
No files matched your search
@@ -4,6 +4,7 @@
|
||||
"description": "ArtPlayer is a modern HTML5 video player",
|
||||
"main": "dist/artplayer.js",
|
||||
"style": "dist/artplayer.css",
|
||||
"types": "types/artplayer.d.ts",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
||||
@@ -54,14 +54,16 @@ class Artplayer extends Emitter {
|
||||
return Emitter;
|
||||
}
|
||||
|
||||
static get validator() {
|
||||
return optionValidator;
|
||||
}
|
||||
|
||||
static get DEFAULTS() {
|
||||
return {
|
||||
container: '#artplayer',
|
||||
url: '',
|
||||
poster: '',
|
||||
title: '',
|
||||
type: '',
|
||||
mimeCodec: '',
|
||||
theme: '#f00',
|
||||
volume: 0.7,
|
||||
isLive: false,
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
import { errorHandle, getExt } from './utils';
|
||||
import config from './config';
|
||||
|
||||
export default class Mse {
|
||||
constructor(art) {
|
||||
this.art = art;
|
||||
if (art.option.mse) {
|
||||
this.init();
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
const { player, events } = this.art;
|
||||
this.setMimeCodec();
|
||||
Object.defineProperty(player, 'returnUrl', {
|
||||
value: () => {
|
||||
this.mediaSource = new MediaSource();
|
||||
const url = URL.createObjectURL(this.mediaSource);
|
||||
this.eventBind();
|
||||
events.destroyEvents.push(() => {
|
||||
URL.revokeObjectURL(url);
|
||||
});
|
||||
return url;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
setMimeCodec() {
|
||||
const { option } = this.art;
|
||||
if (!option.type) {
|
||||
const type = getExt(option.url);
|
||||
errorHandle(
|
||||
Object.keys(config.mimeCodec).includes(type),
|
||||
`Can't find video's type '${type}' from '${option.url}'`,
|
||||
);
|
||||
option.type = type;
|
||||
}
|
||||
|
||||
if (!option.mimeCodec) {
|
||||
const mimeCodec = config.mimeCodec[option.type];
|
||||
errorHandle(mimeCodec, `Can't find video's mimeCodec from ${option.type}`);
|
||||
option.mimeCodec = mimeCodec;
|
||||
}
|
||||
|
||||
errorHandle(
|
||||
'MediaSource' in window && MediaSource.isTypeSupported(option.mimeCodec),
|
||||
`Unsupported MIME type or codec: ${option.mimeCodec}`,
|
||||
);
|
||||
}
|
||||
|
||||
eventBind() {
|
||||
const {
|
||||
option,
|
||||
events: { proxy },
|
||||
} = this.art;
|
||||
const { mediaSource, sourceBufferList, sourceBuffer } = config.mse;
|
||||
mediaSource.events.forEach(eventName => {
|
||||
proxy(this.mediaSource, eventName, event => {
|
||||
this.art.emit(`mediaSource:${event.type}`, event);
|
||||
});
|
||||
});
|
||||
|
||||
sourceBufferList.events.forEach(eventName => {
|
||||
proxy(this.mediaSource.sourceBuffers, eventName, event => {
|
||||
this.art.emit(`sourceBuffers:${event.type}`, event);
|
||||
});
|
||||
proxy(this.mediaSource.activeSourceBuffers, eventName, event => {
|
||||
this.art.emit(`activeSourceBuffers:${event.type}`, event);
|
||||
});
|
||||
});
|
||||
|
||||
this.art.on('mediaSource:sourceopen', () => {
|
||||
this.sourceBuffer = this.mediaSource.addSourceBuffer(option.mimeCodec);
|
||||
sourceBuffer.events.forEach(eventName => {
|
||||
proxy(this.sourceBuffer, eventName, event => {
|
||||
this.art.emit(`sourceBuffer:${event.type}`, event);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
this.art.on('sourceBuffer:updateend', () => {
|
||||
this.mediaSource.endOfStream();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,6 @@ export default {
|
||||
},
|
||||
poster: 'string',
|
||||
title: 'string',
|
||||
type: {
|
||||
type: 'string',
|
||||
},
|
||||
mimeCodec: 'string',
|
||||
theme: 'string',
|
||||
volume: 'number',
|
||||
isLive: 'boolean',
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"include": ["src"],
|
||||
"compilerOptions": {
|
||||
"lib": ["es2015"],
|
||||
"strict": true
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
export default class Artplayer {
|
||||
constructor(option: {
|
||||
container: string | Element;
|
||||
url: string;
|
||||
poster?: string;
|
||||
title?: string;
|
||||
type?: string;
|
||||
mimeCodec?: string;
|
||||
theme?: string;
|
||||
lang?: string;
|
||||
volume?: number;
|
||||
isLive?: boolean;
|
||||
muted?: boolean;
|
||||
autoplay?: boolean;
|
||||
autoSize?: boolean;
|
||||
loop?: boolean;
|
||||
playbackRate?: boolean;
|
||||
aspectRatio?: boolean;
|
||||
screenshot?: boolean;
|
||||
setting?: boolean;
|
||||
hotkey?: boolean;
|
||||
pip?: boolean;
|
||||
mutex?: boolean;
|
||||
fullscreen?: boolean;
|
||||
fullscreenWeb?: boolean;
|
||||
layers?: any[];
|
||||
contextmenu?: any[];
|
||||
quality?: any[];
|
||||
controls?: any[];
|
||||
highlight?: any[];
|
||||
plugins?: any[];
|
||||
whitelist?: any[];
|
||||
thumbnails?: object;
|
||||
subtitle?: object;
|
||||
moreVideoAttr?: object;
|
||||
icons?: object;
|
||||
customType?: object;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user