mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-18 10:41:20 -08:00
分离部分工具函数
This commit is contained in:
1 parent
8ad0605e1a
commit
4658d3f4b4
6 files changed
+38
-37
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import fetchStream from './fetchStream';
|
||||
import readFile from './readFile';
|
||||
import { mergeTypedArrays } from '../utils';
|
||||
import { mergeTypedArrays, getUint8Sum } from '../utils';
|
||||
|
||||
export default class FlvParse {
|
||||
constructor(flv) {
|
||||
@@ -63,9 +63,9 @@ export default class FlvParse {
|
||||
const tag = Object.create(null);
|
||||
tag.tagType = this.read(1);
|
||||
tag.dataSize = this.read(3);
|
||||
tag.Timestamp = this.read(4);
|
||||
tag.StreamID = this.read(3);
|
||||
tag.body = this.read(FlvParse.getBodySum(tag.dataSize));
|
||||
tag.timestamp = this.read(4);
|
||||
tag.streamID = this.read(3);
|
||||
tag.body = this.read(getUint8Sum(tag.dataSize));
|
||||
this.tags.push(tag);
|
||||
this.read(4);
|
||||
}
|
||||
@@ -94,8 +94,4 @@ export default class FlvParse {
|
||||
console.log(this.tags);
|
||||
console.log(types);
|
||||
}
|
||||
|
||||
static getBodySum(arr) {
|
||||
return arr[0] * 256 ** 2 + arr[1] * 256 + arr[2];
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,11 @@ class Flv extends Emitter {
|
||||
constructor(options) {
|
||||
super();
|
||||
this.options = Object.assign({}, Flv.DEFAULTS, options);
|
||||
console.log(this.options);
|
||||
checkSupport(this.options);
|
||||
this.events = new EventProxy(this);
|
||||
this.workers = new CreatWorker(this);
|
||||
this.mediaSource = new CreatMediaSource(this);
|
||||
this.flvData = new FlvParse(this);
|
||||
id += 1;
|
||||
this.id = id;
|
||||
Flv.instances.push(this);
|
||||
@@ -38,13 +41,6 @@ class Flv extends Emitter {
|
||||
return utils;
|
||||
}
|
||||
|
||||
load() {
|
||||
this.events = new EventProxy(this);
|
||||
this.workers = new CreatWorker(this);
|
||||
this.mediaSource = new CreatMediaSource(this);
|
||||
this.flvData = new FlvParse(this);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.events.destroy();
|
||||
this.workers.killAll();
|
||||
|
||||
@@ -20,3 +20,11 @@ export function mergeTypedArrays(a, b) {
|
||||
c.set(b, a.length);
|
||||
return c;
|
||||
}
|
||||
|
||||
export function sleep(ms = 0) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export function getUint8Sum(arr) {
|
||||
return arr.reduce((totle, num, index) => totle + num * 256 ** (arr.length - index - 1), 0);
|
||||
}
|
||||
Reference in new issue
Block a user