mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-13 07:46:17 -08:00
完成fetch
This commit is contained in:
1 parent
765402662f
commit
8ad0605e1a
6 files changed
+68
-59
No files matched your search
+2
-1
@@ -19,7 +19,8 @@
|
||||
<div class="container">
|
||||
<div class="part-top">
|
||||
<div class="config">
|
||||
<input class="urlInput" type="text" value="https://blog.zhw-island.com/assets-cdn/video/one-more-time-one-more-chance-480p.flv">
|
||||
<input class="urlInput" type="text" value="./video/again.flv">
|
||||
<!-- <input class="urlInput" type="text" value="https://blog.zhw-island.com/assets-cdn/video/one-more-time-one-more-chance-480p.flv"> -->
|
||||
<div class="btns">
|
||||
<input class="playBtn" type="button" value="Play">
|
||||
<input class="fileBtn" type="file">
|
||||
|
||||
Binary file not shown.
@@ -506,7 +506,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
flv.emit('flvFetching', value);
|
||||
flv.emit('flvFetching', new Uint8Array(value));
|
||||
controller.enqueue(value);
|
||||
read();
|
||||
}).catch(function (error) {
|
||||
@@ -541,40 +541,41 @@
|
||||
|
||||
classCallCheck(this, FlvParse);
|
||||
|
||||
this.flv = flv;
|
||||
var url = flv.options.url;
|
||||
this.uint8 = new Uint8Array(0);
|
||||
this.index = 0;
|
||||
this.header = null;
|
||||
this.tags = [];
|
||||
this.done = false;
|
||||
flv.on('flvFetchStart', function () {
|
||||
console.log('flvFetchStart');
|
||||
console.log('[flv-fetch-start]');
|
||||
});
|
||||
flv.on('flvFetchCancel', function () {
|
||||
console.log('flvFetchCancel');
|
||||
console.log('[flv-fetch-cancel]');
|
||||
});
|
||||
flv.on('flvFetchError', function (error) {
|
||||
console.log('flvFetchError', error);
|
||||
console.log('[flv-fetch-error]', error);
|
||||
});
|
||||
flv.on('flvFetching', function (value) {
|
||||
_this.uint8 = mergeTypedArrays(_this.uint8, new Uint8Array(value));
|
||||
console.log(_this.uint8.length);
|
||||
flv.on('flvFetching', function (uint8) {
|
||||
_this.uint8 = mergeTypedArrays(_this.uint8, uint8);
|
||||
|
||||
_this.parseHeader();
|
||||
_this.parse();
|
||||
});
|
||||
flv.on('flvFetchEnd', function (value) {
|
||||
console.log('flvFetchEnd');
|
||||
flv.on('flvFetchEnd', function (uint8) {
|
||||
console.log('[flv-fetch-end]');
|
||||
_this.done = true;
|
||||
|
||||
if (value) {
|
||||
_this.uint8 = value;
|
||||
if (uint8) {
|
||||
_this.uint8 = uint8;
|
||||
_this.index = 0;
|
||||
_this.header = null;
|
||||
_this.tags = [];
|
||||
|
||||
_this.parseHeader(); // this.parseTags();
|
||||
|
||||
_this.parse();
|
||||
}
|
||||
|
||||
_this.verify();
|
||||
});
|
||||
var url = flv.options.url;
|
||||
|
||||
if (typeof url === 'string') {
|
||||
fetchStream(flv, url);
|
||||
@@ -584,24 +585,20 @@
|
||||
}
|
||||
|
||||
createClass(FlvParse, [{
|
||||
key: "parseHeader",
|
||||
value: function parseHeader() {
|
||||
key: "parse",
|
||||
value: function parse() {
|
||||
if (this.uint8.length >= 13 && !this.header) {
|
||||
var header = {};
|
||||
var header = Object.create(null);
|
||||
header.signature = this.read(3);
|
||||
header.version = this.read(1);
|
||||
header.flags = this.read(1);
|
||||
header.headersize = this.read(4);
|
||||
this.header = header;
|
||||
this.read(4);
|
||||
console.log(this.header);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "parseTags",
|
||||
value: function parseTags() {
|
||||
|
||||
while (this.index < this.uint8.length) {
|
||||
var tag = {};
|
||||
var tag = Object.create(null);
|
||||
tag.tagType = this.read(1);
|
||||
tag.dataSize = this.read(3);
|
||||
tag.Timestamp = this.read(4);
|
||||
@@ -624,13 +621,21 @@
|
||||
return tempUint8;
|
||||
}
|
||||
}, {
|
||||
key: "verifyTags",
|
||||
value: function verifyTags() {
|
||||
var state = this.tags.some(function (item) {
|
||||
key: "verify",
|
||||
value: function verify() {
|
||||
var types = Object.create(null);
|
||||
this.tags.forEach(function (item) {
|
||||
var tagType = item.tagType[0];
|
||||
return ![18, 9, 8].includes(tagType);
|
||||
|
||||
if (types[tagType]) {
|
||||
types[tagType] += 1;
|
||||
} else {
|
||||
types[tagType] = 1;
|
||||
}
|
||||
});
|
||||
console.log(state ? '验证不通过' : '验证通过');
|
||||
console.log(this.header);
|
||||
console.log(this.tags);
|
||||
console.log(types);
|
||||
}
|
||||
}], [{
|
||||
key: "getBodySum",
|
||||
|
||||
@@ -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/utils/index.js","../../packages/artplayer-plugin-flv/src/utils/checkSupport.js","../../packages/artplayer-plugin-flv/src/eventProxy.js","../../packages/artplayer-plugin-flv/src/creatWorker.js","../../packages/artplayer-plugin-flv/src/config.js","../../packages/artplayer-plugin-flv/src/creatMediaSource.js","../../packages/artplayer-plugin-flv/src/flvParse/fetchStream.js","../../packages/artplayer-plugin-flv/src/flvParse/readFile.js","../../packages/artplayer-plugin-flv/src/flvParse/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 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/creatWorker.js","../../packages/artplayer-plugin-flv/src/config.js","../../packages/artplayer-plugin-flv/src/creatMediaSource.js","../../packages/artplayer-plugin-flv/src/flvParse/fetchStream.js","../../packages/artplayer-plugin-flv/src/flvParse/readFile.js","../../packages/artplayer-plugin-flv/src/flvParse/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 Line truncated
|
||||
@@ -31,7 +31,7 @@ export default function fetchStream(flv, url) {
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
flv.emit('flvFetching', value);
|
||||
flv.emit('flvFetching', new Uint8Array(value));
|
||||
controller.enqueue(value);
|
||||
read();
|
||||
})
|
||||
|
||||
@@ -4,43 +4,43 @@ import { mergeTypedArrays } from '../utils';
|
||||
|
||||
export default class FlvParse {
|
||||
constructor(flv) {
|
||||
this.flv = flv;
|
||||
const { url } = flv.options;
|
||||
this.uint8 = new Uint8Array(0);
|
||||
this.index = 0;
|
||||
this.header = null;
|
||||
this.tags = [];
|
||||
this.done = false;
|
||||
|
||||
flv.on('flvFetchStart', () => {
|
||||
console.log('flvFetchStart');
|
||||
console.log('[flv-fetch-start]');
|
||||
});
|
||||
|
||||
flv.on('flvFetchCancel', () => {
|
||||
console.log('flvFetchCancel');
|
||||
console.log('[flv-fetch-cancel]');
|
||||
});
|
||||
|
||||
flv.on('flvFetchError', error => {
|
||||
console.log('flvFetchError', error);
|
||||
console.log('[flv-fetch-error]', error);
|
||||
});
|
||||
|
||||
flv.on('flvFetching', value => {
|
||||
this.uint8 = mergeTypedArrays(this.uint8, new Uint8Array(value));
|
||||
console.log(this.uint8.length);
|
||||
this.parseHeader();
|
||||
flv.on('flvFetching', uint8 => {
|
||||
this.uint8 = mergeTypedArrays(this.uint8, uint8);
|
||||
this.parse();
|
||||
});
|
||||
|
||||
flv.on('flvFetchEnd', value => {
|
||||
console.log('flvFetchEnd');
|
||||
if (value) {
|
||||
this.uint8 = value;
|
||||
flv.on('flvFetchEnd', uint8 => {
|
||||
console.log('[flv-fetch-end]');
|
||||
this.done = true;
|
||||
if (uint8) {
|
||||
this.uint8 = uint8;
|
||||
this.index = 0;
|
||||
this.header = null;
|
||||
this.tags = [];
|
||||
this.parseHeader();
|
||||
// this.parseTags();
|
||||
this.parse();
|
||||
}
|
||||
this.verify();
|
||||
});
|
||||
|
||||
const { url } = flv.options;
|
||||
if (typeof url === 'string') {
|
||||
fetchStream(flv, url);
|
||||
} else {
|
||||
@@ -48,22 +48,19 @@ export default class FlvParse {
|
||||
}
|
||||
}
|
||||
|
||||
parseHeader() {
|
||||
parse() {
|
||||
if (this.uint8.length >= 13 && !this.header) {
|
||||
const header = {};
|
||||
const header = Object.create(null);
|
||||
header.signature = this.read(3);
|
||||
header.version = this.read(1);
|
||||
header.flags = this.read(1);
|
||||
header.headersize = this.read(4);
|
||||
this.header = header;
|
||||
this.read(4);
|
||||
console.log(this.header);
|
||||
}
|
||||
}
|
||||
|
||||
parseTags() {
|
||||
while (this.index < this.uint8.length) {
|
||||
const tag = {};
|
||||
const tag = Object.create(null);
|
||||
tag.tagType = this.read(1);
|
||||
tag.dataSize = this.read(3);
|
||||
tag.Timestamp = this.read(4);
|
||||
@@ -83,13 +80,19 @@ export default class FlvParse {
|
||||
return tempUint8;
|
||||
}
|
||||
|
||||
verifyTags() {
|
||||
const state = this.tags.some(item => {
|
||||
verify() {
|
||||
const types = Object.create(null);
|
||||
this.tags.forEach(item => {
|
||||
const tagType = item.tagType[0];
|
||||
return ![18, 9, 8].includes(tagType);
|
||||
if (types[tagType]) {
|
||||
types[tagType] += 1;
|
||||
} else {
|
||||
types[tagType] = 1;
|
||||
}
|
||||
});
|
||||
|
||||
console.log(state ? '验证不通过' : '验证通过');
|
||||
console.log(this.header);
|
||||
console.log(this.tags);
|
||||
console.log(types);
|
||||
}
|
||||
|
||||
static getBodySum(arr) {
|
||||
|
||||
Reference in new issue
Block a user