简体   繁体   English

尝试通过websocket流MP3时的DOM异常12

[英]DOM Exception 12 when trying to stream MP3 through websocket

I am currently working on a small project where I want to split an mp3 into frames, send them to a client (browser) through a websocket and then play them back using WebAudio (webkitAudioContext). 我目前正在一个小项目中,我想将mp3拆分为帧,通过websocket将其发送到客户端(浏览器),然后使用WebAudio(webkitAudioContext)进行播放。 My server is running nodejs and to transfer the data as binary, I use binaryJS. 我的服务器正在运行nodejs,并且要以二进制形式传输数据,所以我使用binaryJS。 The browser I am testing with is Chrome 25.0.1354.0 dev, running on Ubuntu 12.04. 我正在测试的浏览器是在Ubuntu 12.04上运行的Chrome 25.0.1354.0 dev。

I have gotten as far as successfully splitting the mp3 into frames, or, at least, based on my tests, it seems to work. 我已经成功地将mp3拆分为多个帧,或者至少根据我的测试,它似乎可以正常工作。 If I write the frames back into a file, mplayer has no problem playing back the file and also parses the header correctly. 如果我将帧写回到文件中,则mplayer播放文件没有问题,并且可以正确解析标头。 Each frame is stored in a nodejs Buffer of the correct size and the last byte of the buffer is always the first byte before the next sync word. 每个帧都存储在大小正确的nodejs缓冲区中,缓冲区的最后一个字节始终是下一个同步字之前的第一个字节。

As an initial test, I am only sending the first MP3 frame. 作为初始测试,我只发送第一个MP3帧。 The client receives the frame successfully (stored in an ArrayBuffer), and the buffer contains the correct data. 客户端成功接收帧(存储在ArrayBuffer中),并且缓冲区包含正确的数据。 However, when I call decode, I get the following message: 但是,当我调用解码时,会收到以下消息:

Uncaught Error: SyntaxError: DOM Exception 12 

My function, where I call decodeAudio, looks like this: 我的函数(我称之为解码音频)如下所示:

streamDone = ->
    bArray = new Uint8Array(arr[0].byteLength)
    console.log "Stream is done, bytes", bArray.length
    context.decodeAudioData bArray, playAudio, err

The initial frame that I am trying to deocde, can be found here . 我要布置的初始框架可以在这里找到。

I have been banging my head in the wall for a couple of days now trying to solve this. 为了解决这个问题,我已经将头撞墙了几天。 Has anyone managed to solve this and sucessfully decoded mp3 frames, and see what I do wrong? 有没有人设法解决这个问题并成功解码了mp3帧,看看我做错了什么? I have found two related question on StackOverflow, but the answers did not help me solve my problem. 我在StackOverflow上发现了两个相关的问题,但是答案并没有帮助我解决问题。 However, according to the accepted answer here , my frame should qualify as a valid mp3 chunk and, thus, be decoded. 但是,根据此处接受的答案,我的帧应符合有效的mp3块的条件,并因此被解码。

Thanks in advance for any help! 在此先感谢您的帮助!

Turns out that a break and some fresh eyes can work wonders, a general code cleanup solved the issue. 事实证明,稍事休息和新鲜的眼神可以创造奇迹,常规代码清除解决了该问题。 If anyone is interested in the code, I published it here . 如果有人对代码感兴趣,我会在这里发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM