mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 23:51:20 -08:00
优化检测支持函数
This commit is contained in:
1 parent
b7e740ae61
commit
f63ae33be7
5 files changed
+34
-41
No files matched your search
@@ -1,17 +1,16 @@
|
||||
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");
|
||||
}
|
||||
export default function checkSupport(mediaElement, url) {
|
||||
errorHandle(mediaElement instanceof HTMLVideoElement, 'The first parameter is not a video tag element');
|
||||
errorHandle(typeof url === 'string', 'The second parameter is not a string type');
|
||||
const MP4H264MimeCodec = 'video/mp4; codecs="avc1.42001E, mp4a.40.2"';
|
||||
const canPlay = mediaElement.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");
|
||||
}
|
||||
@@ -18,16 +18,16 @@ export default class CreatMediaSource {
|
||||
|
||||
config.mediaSource.events.forEach(eventName => {
|
||||
proxy(this.mediaSource, eventName, event => {
|
||||
this.art.emit(`mediaSource:${event.type}`, event);
|
||||
this.flv.emit(`mediaSource:${event.type}`, event);
|
||||
});
|
||||
});
|
||||
|
||||
config.sourceBufferList.events.forEach(eventName => {
|
||||
proxy(this.mediaSource.sourceBuffers, eventName, event => {
|
||||
this.art.emit(`sourceBuffers:${event.type}`, event);
|
||||
this.flv.emit(`sourceBuffers:${event.type}`, event);
|
||||
});
|
||||
proxy(this.mediaSource.activeSourceBuffers, eventName, event => {
|
||||
this.art.emit(`activeSourceBuffers:${event.type}`, event);
|
||||
this.flv.emit(`activeSourceBuffers:${event.type}`, event);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Emitter from 'tiny-emitter';
|
||||
import CheckSupport from './checkSupport';
|
||||
import checkSupport from './checkSupport';
|
||||
import EventProxy from './eventProxy';
|
||||
import CreatMediaSource from './creatMediaSource';
|
||||
import * as utils from './utils';
|
||||
@@ -9,15 +9,10 @@ let id = 0;
|
||||
class Flv extends Emitter {
|
||||
constructor(mediaElement, url) {
|
||||
super();
|
||||
utils.errorHandle(mediaElement instanceof HTMLVideoElement, 'The first parameter is not a video tag element');
|
||||
utils.errorHandle(typeof url === 'string', 'The second parameter is not a string type');
|
||||
checkSupport(mediaElement, url);
|
||||
this.mediaElement = mediaElement;
|
||||
this.url = url;
|
||||
|
||||
this.support = new CheckSupport(this);
|
||||
this.events = new EventProxy(this);
|
||||
this.mediaSource = new CreatMediaSource(this);
|
||||
|
||||
id += 1;
|
||||
this.id = id;
|
||||
Flv.instances.push(this);
|
||||
@@ -36,7 +31,9 @@ class Flv extends Emitter {
|
||||
}
|
||||
|
||||
load() {
|
||||
console.log(this.id);
|
||||
this.events = new EventProxy(this);
|
||||
this.mediaSource = new CreatMediaSource(this);
|
||||
this.emit('load');
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
||||
Reference in new issue
Block a user