改变flv插件加载方式

This commit is contained in:
Harvey Zack committed 2018-12-19 09:20:45 +08:00
1 parent efb5f69dab
commit 7264d0b3a3
11 files changed
+84 -103

No files matched your search

+6 -2
View File
@@ -29,10 +29,14 @@
type: 'flv',
customType: {
flv: function(video, url) {
this.plugins.artplayerPluginFlv.init(video, file || url);
var flv = new Flv({
mediaElement: video,
url: url,
});
flv.load();
},
},
plugins: [artplayerPluginFlv]
});
}
+18 -27
View File
@@ -281,7 +281,9 @@
errorHandle: errorHandle
});
function checkSupport(mediaElement, url) {
function checkSupport(options) {
var mediaElement = options.mediaElement,
url = options.url;
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');
var MP4H264MimeCodec = 'video/mp4; codecs="avc1.42001E, mp4a.40.2"';
@@ -354,7 +356,7 @@
key: "creatUrl",
value: function creatUrl() {
var _this$flv = this.flv,
mediaElement = _this$flv.mediaElement,
mediaElement = _this$flv.options.mediaElement,
destroyEvents = _this$flv.events.destroyEvents;
this.mediaSource = new MediaSource();
var url = URL.createObjectURL(this.mediaSource);
@@ -400,7 +402,7 @@
this.header = {};
this.tags = [];
if (typeof flv.url === 'string') {
if (typeof flv.options.url === 'string') {
this.fromNetwork(flv.url);
} else {
this.fromLocal(flv.url);
@@ -410,7 +412,7 @@
createClass(FlvParse, [{
key: "fromNetwork",
value: function fromNetwork(url) {
console.log(this.flv.url);
console.log(this.flv.options.url);
}
}, {
key: "fromLocal",
@@ -476,15 +478,14 @@
function (_Emitter) {
inherits(Flv, _Emitter);
function Flv(mediaElement, url) {
function Flv(options) {
var _this;
classCallCheck(this, Flv);
_this = possibleConstructorReturn(this, getPrototypeOf(Flv).call(this));
checkSupport(mediaElement, url);
_this.mediaElement = mediaElement;
_this.url = url;
_this.options = Object.assign({}, Flv.DEFAULTS, options);
checkSupport(_this.options);
id += 1;
_this.id = id;
Flv.instances.push(assertThisInitialized(assertThisInitialized(_this)));
@@ -506,6 +507,14 @@
this.emit('destroy');
}
}], [{
key: "DEFAULTS",
get: function get() {
return {
mediaElement: '',
url: ''
};
}
}, {
key: "version",
get: function get() {
return '1.0.6';
@@ -530,25 +539,7 @@
});
window.Flv = Flv;
function artplayerPluginFlv(art) {
var flv = null;
art.on('destroy', function () {
if (flv) {
flv.destroy();
}
});
return {
flv: flv,
init: function init(mediaElement, url) {
flv = new Flv(mediaElement, url);
flv.load();
}
};
}
window.artplayerPluginFlv = artplayerPluginFlv;
exports.default = artplayerPluginFlv;
exports.default = Flv;
Object.defineProperty(exports, '__esModule', { value: true });
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"artplayer-plugin-flv.js","sources":["../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../node_modules/@babel/runtime/helpers/createClass.js","../../node_modules/@babel/runtime/helpers/typeof.js","../../node_modules/@babel/runtime/helpers/assertThisInitialized.js","../../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js","../../node_modules/@babel/runtime/helpers/getPrototypeOf.js","../../node_modules/@babel/runtime/helpers/setPrototypeOf.js","../../node_modules/@babel/runtime/helpers/inherits.js","../../packages/artplayer-plugin-flv/node_modules/tiny-emitter/index.js","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../packages/artplayer-plugin-flv/src/flv/utils/index.js","../../packages/artplayer-plugin-flv/src/flv/utils/checkSupport.js","../../packages/artplayer-plugin-flv/src/flv/eventProxy.js","../../packages/artplayer-plugin-flv/src/flv/config.js","../../packages/artplayer-plugin-flv/src/flv/creatMediaSource.js","../../packages/artplayer-plugin-flv/src/flv/flvParse.js","../../packages/artplayer-plugin-flv/src/flv/index.js","../../packages/artplayer-plugin-flv/src/index.js"],"sourcesContent":["function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck;","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nfunction _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n}\n\nmodule.exports = _createClass;","function _typeof2(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof2(obj); }\n\nfunction _typeof(obj) {\n if (typeof Symbol === \"function\" && _typeof2(Symbol.iterator) === \"symbol\") {\n module.exports = _typeof = function _typeof(obj) {\n return _typeof2(obj);\n };\n } else {\n module.exports = _typeof = function _typeof(obj) {\n return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : _typeof2(obj);\n };\n }\n\n return _typeof(obj);\n}\n\nmodule.exports = _typeof;","function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nmodule.exports = _assertThisInitialized;","var _typeof = require(\"../helpers/typeof\");\n\nvar assertThisInitialized = require(\"./assertThisInitialized\");\n\nfunction _possibleConstructorReturn(self, call) {\n if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) {\n return call;\n }\n\n return assertThisInitialized(self);\n}\n\nmodule.exports = _possibleConstructorReturn;","function _getPrototypeOf(o) {\n module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {\n return o.__proto__ || Object.getPrototypeOf(o);\n };\n return _getPrototypeOf(o);\n}\n\nmodule.exports = _getPrototypeOf;","function _setPrototypeOf(o, p) {\n module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf;","var setPrototypeOf = require(\"./setPrototypeOf\");\n\nfunction _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n writable: true,\n configurable: true\n }\n });\n if (superClass) setPrototypeOf(subClass, superClass);\n}\n\nmodule.exports = _inherits;","function E () {\n // Keep this empty so it's easier to inherit from\n // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)\n}\n\nE.prototype = {\n on: function (name, callback, ctx) {\n var e = this.e || (this.e = {});\n\n (e[name] || (e[name] = [])).push({\n fn: callback,\n ctx: ctx\n });\n\n Line truncated
{"version":3,"file":"artplayer-plugin-flv.js","sources":["../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../node_modules/@babel/runtime/helpers/createClass.js","../../node_modules/@babel/runtime/helpers/typeof.js","../../node_modules/@babel/runtime/helpers/assertThisInitialized.js","../../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js","../../node_modules/@babel/runtime/helpers/getPrototypeOf.js","../../node_modules/@babel/runtime/helpers/setPrototypeOf.js","../../node_modules/@babel/runtime/helpers/inherits.js","../../packages/artplayer-plugin-flv/node_modules/tiny-emitter/index.js","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../packages/artplayer-plugin-flv/src/utils/index.js","../../packages/artplayer-plugin-flv/src/utils/checkSupport.js","../../packages/artplayer-plugin-flv/src/eventProxy.js","../../packages/artplayer-plugin-flv/src/config.js","../../packages/artplayer-plugin-flv/src/creatMediaSource.js","../../packages/artplayer-plugin-flv/src/flvParse.js","../../packages/artplayer-plugin-flv/src/index.js"],"sourcesContent":["function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck;","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nfunction _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n}\n\nmodule.exports = _createClass;","function _typeof2(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof2(obj); }\n\nfunction _typeof(obj) {\n if (typeof Symbol === \"function\" && _typeof2(Symbol.iterator) === \"symbol\") {\n module.exports = _typeof = function _typeof(obj) {\n return _typeof2(obj);\n };\n } else {\n module.exports = _typeof = function _typeof(obj) {\n return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : _typeof2(obj);\n };\n }\n\n return _typeof(obj);\n}\n\nmodule.exports = _typeof;","function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nmodule.exports = _assertThisInitialized;","var _typeof = require(\"../helpers/typeof\");\n\nvar assertThisInitialized = require(\"./assertThisInitialized\");\n\nfunction _possibleConstructorReturn(self, call) {\n if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) {\n return call;\n }\n\n return assertThisInitialized(self);\n}\n\nmodule.exports = _possibleConstructorReturn;","function _getPrototypeOf(o) {\n module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {\n return o.__proto__ || Object.getPrototypeOf(o);\n };\n return _getPrototypeOf(o);\n}\n\nmodule.exports = _getPrototypeOf;","function _setPrototypeOf(o, p) {\n module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf;","var setPrototypeOf = require(\"./setPrototypeOf\");\n\nfunction _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n writable: true,\n configurable: true\n }\n });\n if (superClass) setPrototypeOf(subClass, superClass);\n}\n\nmodule.exports = _inherits;","function E () {\n // Keep this empty so it's easier to inherit from\n // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)\n}\n\nE.prototype = {\n on: function (name, callback, ctx) {\n var e = this.e || (this.e = {});\n\n (e[name] || (e[name] = [])).push({\n fn: callback,\n ctx: ctx\n });\n\n return this;\n },\n\n once: function (name, callback, ctx) {\n var self = Line truncated
@@ -9,7 +9,7 @@ export default class CreatMediaSource {
creatUrl() {
const {
mediaElement,
options: { mediaElement },
events: { destroyEvents },
} = this.flv;
this.mediaSource = new MediaSource();
@@ -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;
@@ -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) {
+52 -17
View 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;
@@ -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");
}