Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demuxer throw error fix #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mp3",
"version": "0.1.0",
"version": "0.1.1",
"description": "An MP3 decoder for Aurora.js",
"peerDependencies": {
"av": "~0.4.0"
Expand Down
52 changes: 28 additions & 24 deletions src/demuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,32 +167,36 @@ var MP3Demuxer = AV.Demuxer.extend(function() {
var off = stream.offset;
var s = new MP3Stream(new AV.Bitstream(stream));

var header = MP3FrameHeader.decode(s);
if (!header)
return this.emit('error', 'Could not find first frame.');

this.emit('format', {
formatID: 'mp3',
sampleRate: header.samplerate,
channelsPerFrame: header.nchannels(),
bitrate: header.bitrate,
floatingPoint: true,
layer: header.layer,
flags: header.flags
});

var sentDuration = this.parseDuration(header, off);
stream.advance(off - stream.offset);

// if there were no Xing/VBRI tags, guesstimate the duration based on data size and bitrate
this.dataSize = 0;
if (!sentDuration) {
this.on('end', function() {
this.emit('duration', this.dataSize * 8 / header.bitrate * 1000 | 0);
try {
var header = MP3FrameHeader.decode(s);
if (!header)
return this.emit('error', 'Could not find first frame.');

this.emit('format', {
formatID: 'mp3',
sampleRate: header.samplerate,
channelsPerFrame: header.nchannels(),
bitrate: header.bitrate,
floatingPoint: true,
layer: header.layer,
flags: header.flags
});
}

this.sentInfo = true;
var sentDuration = this.parseDuration(header, off);
stream.advance(off - stream.offset);

// if there were no Xing/VBRI tags, guesstimate the duration based on data size and bitrate
this.dataSize = 0;
if (!sentDuration) {
this.on('end', function() {
this.emit('duration', this.dataSize * 8 / header.bitrate * 1000 | 0);
});
}

this.sentInfo = true;
} catch (e) {
return this.emit('error', e.message);
}
}

while (stream.available(1)) {
Expand Down