优化结构

This commit is contained in:
Harvey Zack committed 2018-12-14 17:03:41 +08:00
1 parent c6869686c3
commit f2658673dc
6 files changed
+369 -404

No files matched your search

@@ -1,6 +1,7 @@
export default class CreatMediaSource {
constructor(art) {
constructor(flv) {
this.mediaSource = new MediaSource();
this.url = URL.createObjectURL(this.mediaSource);
flv.mediaElement.src = this.url;
}
}
+4 -26
View File
@@ -1,40 +1,18 @@
import Emitter from 'tiny-emitter';
import CheckSupport from './checkSupport';
import CreatMediaSource from './creatMediaSource';
import { errorHandle } from './utils';
class Flv extends Emitter {
constructor(mediaElement, url) {
super();
this.support = new CheckSupport();
if (mediaElement) {
this.attachMediaElement(mediaElement);
}
if (url) {
this.loadUrl(url);
}
}
attachMediaElement(mediaElement) {
errorHandle(
mediaElement instanceof HTMLVideoElement && mediaElement.tagName === 'VIDEO',
"The 'mediaElement' does not seem to be a HTMLVideoElement",
);
this.mediaElement = mediaElement;
return this;
}
loadUrl(url) {
const type = typeof url;
errorHandle(type === 'string', `The 'url' require 'string' type, but got '${type}'`);
this.url = url;
return this;
this.support = new CheckSupport(this);
this.mediaSource = new CreatMediaSource(this);
}
start() {
this.mediaSource = new CreatMediaSource();
console.log('start');
return this;
destroy() {
console.log(this);
}
}
+12 -9
View File
@@ -1,16 +1,19 @@
import Flv from './flv';
function artplayerPluginFlv(art) {
const {
template: { $video },
} = art;
const flv = new Flv($video);
let flv = null;
art.on('destroy', () => {
if (flv) {
flv.destroy();
}
});
return {
load: url =>
new Promise(resolve => {
flv.loadUrl(url).start();
return resolve(flv.mediaSource.url);
}),
flv,
init: (mediaElement, url) => {
flv = new Flv(mediaElement, url);
},
};
}