zhuker / lamejs

mp3 encoder in javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot read properties of undefined (reading 'println')

guest271314 opened this issue · comments

I have been using lamejs for a while now with this

export {lamejs}
const { lamejs } = await import(`${this.src.origin}/lame.min.js`);
this.mp3encoder = new lamejs.Mp3Encoder(2, 44100, 128);
this.mp3controller = void 0;
this.mp3stream = new ReadableStream({
   start: (_) => {
     return (this.mp3controller = _);
   },
});

later

if (this.mimeType.includes('mp3')) {
  const mp3buf = this.mp3encoder.encodeBuffer(
     leftChannel,
     rightChannel
  );
  if (mp3buf.length > 0) {
    this.mp3controller.enqueue(new Uint8Array(mp3buf));
  }
}

After less than 10 writes an error is thrown

Error: Cannot read properties of undefined (reading 'println')
    at BitStream.format_bitstream (lame.all.js:3500:24)
    at Encoder.lame_encode_mp3_frame (lame.all.js:9998:12)
    at lame_encode_frame (lame.all.js:15151:28)
    at lame_encode_buffer_sample (lame.all.js:15130:23)
    at Lame.lame_encode_buffer (lame.all.js:14996:16)
    at Mp3Encoder.encodeBuffer (lame.all.js:15445:24)
    at Object.write (<anonymous>:252:54)

The only thing that changed is updating Chromium DevChannel over the past few days.

Adjusting kbps to 256 or greater fixes the issue.