mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-26 00:31:20 -08:00
分离flv文件夹
This commit is contained in:
1 parent
2e0d70292b
commit
f8400002c2
9 files changed
+339
-54
No files matched your search
@@ -1,18 +0,0 @@
|
||||
export default function checkSupport(art) {
|
||||
const {
|
||||
utils: { errorHandle },
|
||||
config: { mimeCodec },
|
||||
} = art.constructor;
|
||||
|
||||
const {
|
||||
template: { $video },
|
||||
} = art;
|
||||
|
||||
const canPlay = $video.canPlayType(mimeCodec.mp4);
|
||||
errorHandle(
|
||||
window.MediaSource &&
|
||||
window.MediaSource.isTypeSupported(mimeCodec.mp4) &&
|
||||
(canPlay === 'probably' || canPlay === 'maybe'),
|
||||
`Unsupported MIME type or codec: ${mimeCodec.mp4}`,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { errorHandle } from './utils';
|
||||
|
||||
export default class CheckSupport {
|
||||
constructor() {
|
||||
const MP4H264MimeCodec = 'video/mp4; codecs="avc1.42001E, mp4a.40.2"';
|
||||
const videoElement = window.document.createElement('video');
|
||||
const canPlay = videoElement.canPlayType(MP4H264MimeCodec);
|
||||
errorHandle(
|
||||
window.MediaSource &&
|
||||
window.MediaSource.isTypeSupported(MP4H264MimeCodec) &&
|
||||
(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.
@@ -0,0 +1,16 @@
|
||||
import Emitter from 'tiny-emitter';
|
||||
import CheckSupport from './checkSupport';
|
||||
import CreatMediaSource from './creatMediaSource';
|
||||
|
||||
class Flv extends Emitter {
|
||||
constructor(mediaElement, url) {
|
||||
super();
|
||||
this.mediaElement = mediaElement;
|
||||
this.url = url;
|
||||
this.support = new CheckSupport();
|
||||
this.mediaSource = new CreatMediaSource();
|
||||
}
|
||||
}
|
||||
|
||||
window.Flv = Flv;
|
||||
export default Flv;
|
||||
@@ -0,0 +1,15 @@
|
||||
export class FlvError extends Error {
|
||||
constructor(message, context) {
|
||||
super(message);
|
||||
if (typeof Error.captureStackTrace === 'function') {
|
||||
Error.captureStackTrace(this, context || this.constructor);
|
||||
}
|
||||
this.name = 'FlvError';
|
||||
}
|
||||
}
|
||||
|
||||
export function errorHandle(condition, msg) {
|
||||
if (!condition) {
|
||||
throw new FlvError(msg);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,15 @@
|
||||
import checkSupport from './checkSupport';
|
||||
import CreatMediaSource from './creatMediaSource';
|
||||
|
||||
class Flv {
|
||||
constructor(art) {
|
||||
checkSupport(art);
|
||||
this.mediaSource = new CreatMediaSource(art);
|
||||
this.load = url => {
|
||||
console.log(url);
|
||||
};
|
||||
}
|
||||
}
|
||||
import Flv from './flv';
|
||||
|
||||
function artplayerPluginFlv(art) {
|
||||
const flv = new Flv(art);
|
||||
const {
|
||||
template: { $video },
|
||||
} = art;
|
||||
return {
|
||||
load: url => new Promise(resolve => {
|
||||
flv.load(url);
|
||||
return resolve(flv.mediaSource.url);
|
||||
}),
|
||||
load: url =>
|
||||
new Promise(resolve => {
|
||||
const flv = new Flv($video, url);
|
||||
return resolve(flv.mediaSource.url);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user