mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-28 10:31:20 -08:00
add creatWorker
This commit is contained in:
1 parent
6cc89edcd9
commit
39f8c157ac
9 files changed
+222
-56
No files matched your search
@@ -7,18 +7,21 @@ export default function fetchStream(flv, url) {
|
||||
response.ok && response.status >= 200 && response.status <= 299,
|
||||
`${response.status} ${response.statusText}`,
|
||||
);
|
||||
const contentLength = response.headers.get('content-length');
|
||||
const contentType = response.headers.get('content-type');
|
||||
// errorHandle(contentLength, 'Content-Length response header unavailable');
|
||||
errorHandle(contentType.includes('x-flv'), 'The resource does not seem to be a flv file');
|
||||
flv.emit('flvFetchInfo', {
|
||||
type: contentType,
|
||||
length: contentLength,
|
||||
});
|
||||
return new Response(
|
||||
new ReadableStream({
|
||||
start(controller) {
|
||||
const reader = response.body.getReader();
|
||||
|
||||
flv.on('destroy', () => {
|
||||
reader.cancel();
|
||||
});
|
||||
|
||||
flv.on('readerCancel', () => {
|
||||
reader.cancel();
|
||||
});
|
||||
|
||||
(function read() {
|
||||
reader
|
||||
.read()
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
import fetchStream from './fetchStream';
|
||||
import readFile from './readFile';
|
||||
import { mergeTypedArrays } from '../utils';
|
||||
|
||||
export default class FlvParse {
|
||||
constructor(flv) {
|
||||
this.flv = flv;
|
||||
this.uint8 = [];
|
||||
this.uint8 = new Int8Array(0);
|
||||
this.index = 0;
|
||||
this.header = {};
|
||||
this.header = null;
|
||||
this.tags = [];
|
||||
|
||||
flv.on('flvFetchStart', () => {
|
||||
console.log('flvFetchStart');
|
||||
});
|
||||
|
||||
flv.on('flvFetchInfo', info => {
|
||||
console.log('flvFetchInfo', info);
|
||||
});
|
||||
|
||||
flv.on('flvFetchCancel', () => {
|
||||
console.log('flvFetchCancel');
|
||||
});
|
||||
@@ -26,13 +23,17 @@ export default class FlvParse {
|
||||
});
|
||||
|
||||
flv.on('flvFetching', value => {
|
||||
console.log(value);
|
||||
this.uint8 = mergeTypedArrays(this.uint8, value);
|
||||
console.log(this.uint8.length);
|
||||
this.parseHeader();
|
||||
});
|
||||
|
||||
flv.on('flvFetchEnd', value => {
|
||||
console.log('flvFetchEnd', value);
|
||||
console.log('flvFetchEnd');
|
||||
if (value) {
|
||||
this.uint8 = value;
|
||||
this.parseHeader();
|
||||
// this.parseTags();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -44,12 +45,20 @@ export default class FlvParse {
|
||||
}
|
||||
}
|
||||
|
||||
parse() {
|
||||
this.header.signature = this.read(3);
|
||||
this.header.version = this.read(1);
|
||||
this.header.flags = this.read(1);
|
||||
this.header.headersize = this.read(4);
|
||||
this.read(4);
|
||||
parseHeader() {
|
||||
if (this.uint8.length >= 13 && !this.header) {
|
||||
const header = {};
|
||||
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 = {};
|
||||
tag.tagType = this.read(1);
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
export default function readFile(flv, file) {
|
||||
flv.emit('flvFetchStart');
|
||||
flv.emit('flvFetchInfo', {
|
||||
type: file.type,
|
||||
length: file.size,
|
||||
});
|
||||
const { proxy } = flv.events;
|
||||
const reader = new FileReader();
|
||||
proxy(reader, 'load', e => {
|
||||
|
||||
Reference in new issue
Block a user