mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-19 03:11:20 -08:00
成功读取tags
This commit is contained in:
1 parent
52458bb95e
commit
3a50f7ea86
8 files changed
+170
-18
No files matched your search
@@ -2,6 +2,7 @@ import Emitter from 'tiny-emitter';
|
||||
import checkSupport from './utils/checkSupport';
|
||||
import EventProxy from './eventProxy';
|
||||
import CreatMediaSource from './creatMediaSource';
|
||||
import LoadFile from './loadFile';
|
||||
import * as utils from './utils';
|
||||
import config from './config';
|
||||
|
||||
@@ -33,6 +34,7 @@ class Flv extends Emitter {
|
||||
load() {
|
||||
this.events = new EventProxy(this);
|
||||
this.mediaSource = new CreatMediaSource(this);
|
||||
this.file = new LoadFile(this);
|
||||
this.emit('load');
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
export default class LoadFile {
|
||||
constructor(flv) {
|
||||
this.flv = flv;
|
||||
this.uint8 = [];
|
||||
this.index = 0;
|
||||
this.header = {};
|
||||
this.tags = [];
|
||||
if (typeof flv.url === 'string') {
|
||||
this.fromNetwork(flv.url);
|
||||
} else {
|
||||
this.fromLocal(flv.url);
|
||||
}
|
||||
}
|
||||
|
||||
fromNetwork(url) {
|
||||
console.log(this.flv.url);
|
||||
}
|
||||
|
||||
fromLocal(file) {
|
||||
const {
|
||||
events: { proxy },
|
||||
} = this.flv;
|
||||
const reader = new FileReader();
|
||||
proxy(reader, 'load', e => {
|
||||
const buffer = e.target.result;
|
||||
this.uint8 = new Uint8Array(buffer);
|
||||
this.parse();
|
||||
});
|
||||
reader.readAsArrayBuffer(file);
|
||||
}
|
||||
|
||||
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);
|
||||
while (this.index < this.uint8.length) {
|
||||
const tag = {};
|
||||
tag.tagType = this.read(1);
|
||||
tag.dataSize = this.read(3);
|
||||
tag.Timestamp = this.read(4);
|
||||
tag.StreamID = this.read(3);
|
||||
tag.body = this.read(LoadFile.getBodySum(tag.dataSize));
|
||||
this.tags.push(tag);
|
||||
this.read(4);
|
||||
}
|
||||
}
|
||||
|
||||
read(length) {
|
||||
const tempUint8 = [];
|
||||
for (let i = 0; i < length; i += 1) {
|
||||
tempUint8.push(this.uint8[this.index]);
|
||||
this.index += 1;
|
||||
}
|
||||
return tempUint8;
|
||||
}
|
||||
|
||||
static getBodySum(arr) {
|
||||
return arr[0] * 256 ** 2 + arr[1] * 256 + arr[2];
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@ import { errorHandle } from '.';
|
||||
|
||||
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');
|
||||
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(
|
||||
|
||||
Reference in new issue
Block a user