mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-22 13:21:20 -08:00
优化mse
This commit is contained in:
1 parent
9c4daf3c1d
commit
c7c9e0a311
3 files changed
+47
-43
No files matched your search
@@ -5,12 +5,26 @@ export default class Mse {
|
||||
constructor(art) {
|
||||
this.art = art;
|
||||
if (art.option.mse) {
|
||||
this.setMimeCodec();
|
||||
this.setVideoSrc();
|
||||
this.eventBind();
|
||||
this.init();
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
const { player, events } = this.art;
|
||||
this.setMimeCodec();
|
||||
Object.defineProperty(player, 'mountUrl', {
|
||||
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) {
|
||||
@@ -27,24 +41,11 @@ export default class Mse {
|
||||
errorHandle(mimeCodec, `Can't find video's mimeCodec from ${option.type}`);
|
||||
option.mimeCodec = mimeCodec;
|
||||
}
|
||||
}
|
||||
|
||||
setVideoSrc() {
|
||||
const { option, player, events } = this.art;
|
||||
errorHandle(
|
||||
'MediaSource' in window && MediaSource.isTypeSupported(option.mimeCodec),
|
||||
`Unsupported MIME type or codec: ${option.mimeCodec}`,
|
||||
);
|
||||
this.mediaSource = new MediaSource();
|
||||
Object.defineProperty(player, 'mountUrl', {
|
||||
value: () => {
|
||||
this.url = URL.createObjectURL(this.mediaSource);
|
||||
events.destroyEvents.push(() => {
|
||||
URL.revokeObjectURL(this.url);
|
||||
});
|
||||
return this.url;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
eventBind() {
|
||||
|
||||
Reference in new issue
Block a user