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

error when i execute Asset.fromFile.It seams a bug #188

Open
publicocean0 opened this issue May 24, 2017 · 3 comments
Open

error when i execute Asset.fromFile.It seams a bug #188

publicocean0 opened this issue May 24, 2017 · 3 comments

Comments

@publicocean0
Copy link

publicocean0 commented May 24, 2017

var asset = AV.Asset.fromFile(evt.target.files[0]);
https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3 downloaded in local.
Error: bad main_data_begin pointer
at Layer3.decode (mp3.js:5061)
at MP3Frame.decode (mp3.js:365)
at Class.readChunk (mp3.js:46)
at Class.Decoder.decode (decoder.js:72)
at Class. (decoder.js:46)
at Class.EventEmitter.emit (events.js:64)
at Class.readChunk (mp3.js:326)
at FileSource. (demuxer.js:34)
at FileSource.EventEmitter.emit (events.js:64)
at FileReader. (file.coffee:25)

@publicocean0 publicocean0 changed the title Not blocking error when i execute fromFile Not blocking error when i execute Asset.fromFile May 26, 2017
@publicocean0 publicocean0 changed the title Not blocking error when i execute Asset.fromFile error when i execute Asset.fromFile.It seams a bug May 26, 2017
@publicocean0
Copy link
Author

In addition now i tried to decode this new mp3 ... in this case .... decoding is never executed.
For test ... download mp3
https://soundcloud.com/theokouroumlis/breathe-in

and asset = AV.Asset.fromFile(evt.target.files[0]);

@ButzYung
Copy link

ButzYung commented May 28, 2017

In short, decoding a MP3 stream into buffer using functions like .decode() is never reliable. For most MP3s, you will almost always get some "glitches" during the decoding resulting in errors (usually 'bad main_data_begin pointer'). A workaround is to ignore those minor errors by editing mp3.js.

@publicocean0
Copy link
Author

publicocean0 commented May 29, 2017

I find the same problem using av.player .... i solved temporaly the problem hard coding to skip the exception .
I didnt used anyway decode function ... but onData event for sending the pcm data to my player.... there is a bug in decoder.... it happens always with the same files.

I tried to send pcm data to this class




	
var SoundBuffer =  function SoundBuffer(ctx, sampleRate, bufferSize, logger,start,stop) {
        if (bufferSize === void 0) { bufferSize = 100; }
          if (sampleRate===void 0) sampleRate=ctx.sampleRate;

        var chunks = [];
        var downloading = false,lastAction=Promise.resolve();
        var startTime = 0;
        var lastChunkOffset = 0;
    
    
    var createChunk = function (chunk) {
        var audioBuffer = ctx.createBuffer(2, chunk.length, sampleRate);
        audioBuffer.getChannelData(0).set(chunk);
        var source = ctx.createBufferSource();
        source.buffer = audioBuffer;
        source.connect(ctx.destination);
        source.onended = function (e) {
            chunks.splice(chunks.indexOf(source), 1);
            if (! downloading && chunks.length < (bufferSize / 2)) {
				downloading=true;
				start();
			}
            if (chunks.length == 0) {
                isPlaying = false;
                startTime = 0;
                lastChunkOffset = 0;
            }
        };
        return source;
    };
   var log = function (data) {
       
        
        if (logger)    logger( "SoundBuffer : " + data);
        
    };
    this.addChunk = function (data) {
		downloading=true;
      
            log("chunk accepted");
            var chunk = createChunk(data);
            chunk.start(startTime + lastChunkOffset);
            lastChunkOffset += chunk.buffer.duration;
            chunks.push(chunk);
            if (chunks.length >= bufferSize && downloading){
			
	            downloading=false;
	       
			    stop()
			}
        
      
    };
 
}

it works when there is not that exception.
This solution permits to read infinite buffers without out of memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants