mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 22:53:21 -08:00
优化结构
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user