简体   繁体   English

WebAudioAPI decodeAudioData() 在 iOS 14 Safari 上给出 null 错误

[英]WebAudioAPI decodeAudioData() giving null error on iOS 14 Safari

I have an mp3 audio stream player that works well in every desktop browser, using MediaSourceExtensions with a fallback to WebAudioAPI for those browsers that do not support MSE.我有一个 mp3 音频 stream 播放器,它在每个桌面浏览器中都运行良好,使用 MediaSourceExtensions 并为那些不支持 MSE 的浏览器使用 WebAudioAPI。 iOS Safari is one such browser, and should theoretically support mp3 decoding via the Web Audio API without issues. iOS Safari 就是这样一种浏览器,理论上应该支持通过 Web 音频 ZDB974238714CA8ACED638 解码 mp3 没有问题。

I've been struggling to get iOS Safari to properly play the mp3 audio chunks that are being returned from the stream.我一直在努力让 iOS Safari 正确播放从 stream 返回的 mp3 音频块。 So far, it's the only browser that seems to have issues and I can't for the life of me figure out what's going on.到目前为止,它是唯一一个似乎有问题的浏览器,我一生都无法弄清楚发生了什么。 Sadly, there isn't a whole lot of information on corner cases like this and the other questions here on StackOverflow haven't been any help.可悲的是,关于此类极端案例的信息并不多,StackOverflow 上的其他问题也没有任何帮助。

Here's the relevant part of my js code where things are getting hung up.这是我的 js 代码的相关部分,其中的事情被挂断了。 It's a callback function for an async fetch() process that's grabbing the mp3 data from the stream.这是一个回调 function 用于从 stream 获取 mp3 数据的异步fetch()进程。

async function pushStream(value) {
    // Web Audio streaming for browsers that don't support MSE
    if (usingWebAudio) {
        // convert the stream UInt8Array to an ArrayBuffer
        var dataBuffer = value.stream.buffer;
        // decode the raw mp3 chunks
        audCtx.decodeAudioData(dataBuffer, function(newData) {
            // add the decoded data to the buffer
            console.log("pushing new audio data to buffer");
            webAudioBuffer.push(newData);
            // if we have audio in the buffer, play it
            if (webAudioBuffer.length) {
                scheduleWebAudio();
            }
        }, function(e) {
            console.error(e);
        });

What I'm seeing is the error callback being fired and printing null: null as its error message (very helpful).我看到的是错误回调被触发并打印null: null作为其错误消息(非常有帮助)。 Every so often, I will see the console print pushing new audio data to buffer , but this seems to only happen about once every few minutes while the stream is playing.每隔一段时间,我会看到控制台打印pushing new audio data to buffer ,但这似乎每隔几分钟就会发生一次,而 stream 正在播放。 Almost all the stream data is erroring out during the decode and the lack of useful error messages is preventing me from figuring out why.几乎所有的 stream 数据在解码过程中都会出错,并且缺少有用的错误消息使我无法弄清楚原因。

As far as I can tell, iOS safari should support mp3 streams without any issues.据我所知,iOS safari 应该支持 mp3 流,没有任何问题。 It also should support the decodeAudioData() function.它还应该支持decodeAudioData() function。 Most of the other answers I was able to find related to trying to play audio before the user interacts with the screen.我能找到的大多数其他答案都与在用户与屏幕交互之前尝试播放音频有关。 In my case, I start the audio using a play button on the page so I don't believe that's the problem either.就我而言,我使用页面上的播放按钮开始播放音频,所以我也不认为这是问题所在。

One final thing, I'm developing on Windows and using the remotedebug iOS adapter .最后一件事,我正在开发 Windows 并使用 远程调试 iOS 适配器 This could possibly be the reason why I'm not getting useful debug messages, however all other debug and error prints seem to work fine so I don't believe that's the case.这可能是我没有收到有用的调试消息的原因,但是所有其他调试和错误打印似乎都可以正常工作,所以我认为情况并非如此。

Thanks in advance for any help!提前感谢您的帮助!

Unfortunately there is a bug in Safari which causes it to reject the decodeAudioData() promise with null.不幸的是,Safari 中存在一个错误,导致它拒绝decodeAudioData() promise 和 null。 From my experience this happens in cases where it should actually reject the promise with an EncodingError instead.根据我的经验,这种情况发生在它实际上应该用EncodingError拒绝 promise 的情况下。

The bug can be reproduced by asking Safari do decode an image.可以通过询问 Safari 对图像进行解码来重现该错误。 https://github.com/chrisguttandin/standardized-audio-context/blob/9c705bd2e5d8a774b93b07c3b203c8f343737988/test/expectation/safari/any/offline-audio-context-constructor.js#L648-L663 https://github.com/chrisguttandin/standardized-audio-context/blob/9c705bd2e5d8a774b93b07c3b203c8f343737988/test/expectation/safari/any/offline-audio-context-L663

In general decodeAudioData() can only handle full files.一般来说decodeAudioData()只能处理完整的文件。 It isn't capable of decoding a file in chunks.它不能以块的形式解码文件。 The WebCodecs API is meant to solve that but I guess it won't be available on iOS anytime soon. WebCodecs API旨在解决这个问题,但我想它不会很快在 iOS 上可用。

However there is one trick that works with MP3s because of their internal structure.然而,由于 MP3 的内部结构,有一个技巧适用于 MP3。 MP3s are built out of chunks themselves and any number of those chunks form a technically valid MP3. MP3 是由块本身构成的,任何数量的这些块构成技术上有效的 MP3。 That means you can pre-process your data by making sure that each of the buffers that you pass on to decodeAudioData() begins and ends exactly at those internal chunk boundaries.这意味着您可以通过确保传递给decodeAudioData()的每个缓冲区恰好在这些内部块边界处开始和结束来预处理数据。 The phonograph library does for example follow that principle.例如,留声机库确实遵循该原则。

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

相关问题 decodeAudioData返回null错误 - decodeAudioData returning a null error 在Chrome中接收“ decodeAudioData错误null” - Receiving “decodeAudioData error null” in Chrome Safari 调用 decodeAudioData 错误,Chrome 工作时为 null - Safari call to decodeAudioData errors with null where Chrome works Safari对**运算符给出错误 - Safari Giving Error for ** Operator 在iOS上没有用户交互的情况下更改WebAudioAPI中的声音 - Change the sound in WebAudioAPI with no user interaction on iOS Web Audio decodeAudioData iOS上的分块音频 - Web Audio decodeAudioData iOS on chunked dash audio Reactjs Webapp仅在Safari浏览器中给出错误-'undefined'不是函数(评估'ReactElementValidator.createElement.bind(null,type)' - Reactjs webapp giving error only in Safari browser - 'undefined' is not a function (evaluating 'ReactElementValidator.createElement.bind(null,type)' navigator.share 文件不适用于 iOS 14 Safari - navigator.share file not working on iOS 14 Safari Javascript Safari / IOS 15 - 14 上的音频上下文不再工作 - Javascript audio context on Safari / IOS 15 - 14 dont work anymore Firebase 动态链接在 iOS 14 上的 Safari 中留下空白页 - Firebase dynamic link leaves behind a blank page in Safari on iOS 14
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM