mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 22:01:20 -08:00
改变flv插件加载方式
This commit is contained in:
1 parent
efb5f69dab
commit
7264d0b3a3
11 files changed
+84
-103
No files matched your search
File renamed without changes.
+1
-1
@@ -9,7 +9,7 @@ export default class CreatMediaSource {
|
||||
|
||||
creatUrl() {
|
||||
const {
|
||||
mediaElement,
|
||||
options: { mediaElement },
|
||||
events: { destroyEvents },
|
||||
} = this.flv;
|
||||
this.mediaSource = new MediaSource();
|
||||
File renamed without changes.
@@ -1,52 +0,0 @@
|
||||
import Emitter from 'tiny-emitter';
|
||||
import checkSupport from './utils/checkSupport';
|
||||
import EventProxy from './eventProxy';
|
||||
import CreatMediaSource from './creatMediaSource';
|
||||
import FlvParse from './flvParse';
|
||||
import * as utils from './utils';
|
||||
import config from './config';
|
||||
|
||||
let id = 0;
|
||||
class Flv extends Emitter {
|
||||
constructor(mediaElement, url) {
|
||||
super();
|
||||
checkSupport(mediaElement, url);
|
||||
this.mediaElement = mediaElement;
|
||||
this.url = url;
|
||||
|
||||
id += 1;
|
||||
this.id = id;
|
||||
Flv.instances.push(this);
|
||||
}
|
||||
|
||||
static get version() {
|
||||
return '__VERSION__';
|
||||
}
|
||||
|
||||
static get config() {
|
||||
return config;
|
||||
}
|
||||
|
||||
static get utils() {
|
||||
return utils;
|
||||
}
|
||||
|
||||
load() {
|
||||
this.events = new EventProxy(this);
|
||||
this.mediaSource = new CreatMediaSource(this);
|
||||
this.flvData = new FlvParse(this);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.events.destroy();
|
||||
Flv.instances.splice(Flv.instances.indexOf(this), 1);
|
||||
this.emit('destroy');
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(Flv, 'instances', {
|
||||
value: [],
|
||||
});
|
||||
|
||||
window.Flv = Flv;
|
||||
export default Flv;
|
||||
+2
-2
@@ -5,7 +5,7 @@ export default class FlvParse {
|
||||
this.index = 0;
|
||||
this.header = {};
|
||||
this.tags = [];
|
||||
if (typeof flv.url === 'string') {
|
||||
if (typeof flv.options.url === 'string') {
|
||||
this.fromNetwork(flv.url);
|
||||
} else {
|
||||
this.fromLocal(flv.url);
|
||||
@@ -13,7 +13,7 @@ export default class FlvParse {
|
||||
}
|
||||
|
||||
fromNetwork(url) {
|
||||
console.log(this.flv.url);
|
||||
console.log(this.flv.options.url);
|
||||
}
|
||||
|
||||
fromLocal(file) {
|
||||
@@ -1,22 +1,57 @@
|
||||
import Flv from './flv';
|
||||
import Emitter from 'tiny-emitter';
|
||||
import checkSupport from './utils/checkSupport';
|
||||
import EventProxy from './eventProxy';
|
||||
import CreatMediaSource from './creatMediaSource';
|
||||
import FlvParse from './flvParse';
|
||||
import * as utils from './utils';
|
||||
import config from './config';
|
||||
|
||||
function artplayerPluginFlv(art) {
|
||||
let flv = null;
|
||||
let id = 0;
|
||||
class Flv extends Emitter {
|
||||
constructor(options) {
|
||||
super();
|
||||
this.options = Object.assign({}, Flv.DEFAULTS, options);
|
||||
checkSupport(this.options);
|
||||
id += 1;
|
||||
this.id = id;
|
||||
Flv.instances.push(this);
|
||||
}
|
||||
|
||||
art.on('destroy', () => {
|
||||
if (flv) {
|
||||
flv.destroy();
|
||||
}
|
||||
});
|
||||
static get DEFAULTS() {
|
||||
return {
|
||||
mediaElement: '',
|
||||
url: '',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
flv,
|
||||
init: (mediaElement, url) => {
|
||||
flv = new Flv(mediaElement, url);
|
||||
flv.load();
|
||||
},
|
||||
};
|
||||
static get version() {
|
||||
return '__VERSION__';
|
||||
}
|
||||
|
||||
static get config() {
|
||||
return config;
|
||||
}
|
||||
|
||||
static get utils() {
|
||||
return utils;
|
||||
}
|
||||
|
||||
load() {
|
||||
this.events = new EventProxy(this);
|
||||
this.mediaSource = new CreatMediaSource(this);
|
||||
this.flvData = new FlvParse(this);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.events.destroy();
|
||||
Flv.instances.splice(Flv.instances.indexOf(this), 1);
|
||||
this.emit('destroy');
|
||||
}
|
||||
}
|
||||
|
||||
window.artplayerPluginFlv = artplayerPluginFlv;
|
||||
export default artplayerPluginFlv;
|
||||
Object.defineProperty(Flv, 'instances', {
|
||||
value: [],
|
||||
});
|
||||
|
||||
window.Flv = Flv;
|
||||
export default Flv;
|
||||
+4
-1
@@ -1,11 +1,13 @@
|
||||
import { errorHandle } from '.';
|
||||
|
||||
export default function checkSupport(mediaElement, url) {
|
||||
export default function checkSupport(options) {
|
||||
const { mediaElement, url } = options;
|
||||
errorHandle(mediaElement instanceof HTMLVideoElement, 'The first parameter is not a video tag element');
|
||||
errorHandle(
|
||||
typeof url === 'string' || (url instanceof File && url.type === 'video/x-flv'),
|
||||
'The second parameter is not a string type or flv file',
|
||||
);
|
||||
|
||||
const MP4H264MimeCodec = 'video/mp4; codecs="avc1.42001E, mp4a.40.2"';
|
||||
const canPlay = mediaElement.canPlayType(MP4H264MimeCodec);
|
||||
errorHandle(
|
||||
@@ -14,6 +16,7 @@ export default function checkSupport(mediaElement, url) {
|
||||
(canPlay === 'probably' || canPlay === 'maybe'),
|
||||
`Unsupported MIME type or codec: ${MP4H264MimeCodec}`,
|
||||
);
|
||||
|
||||
errorHandle(typeof window.Promise === 'function', "Unsupported 'Promise' method");
|
||||
errorHandle(typeof window.fetch === 'function', "Unsupported 'fetch' method");
|
||||
}
|
||||
File renamed without changes.
Reference in new issue
Block a user