mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 06:31: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
@@ -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',
|
||||
|
||||
Reference in new issue
Block a user