Tone.js 无法在 iOS 上播放音频
我有一个使用 Tone.js 的应用程序,并且专门使用 GrainPlayer 对象。 它在不同操作系统和设备上的不同浏览器上运行得非常好...... iOS 除外。我个人没有 iOS 设备,但客户向我显示 iOS 没有播放音频。它也不仅限于野生动物园;其设备上的其他浏览器也不会播放音频。
我知道这是 Tone.js 特有的问题,因为我还使用 Howler.js 来处理一些不需要 Tone GrainPlayer 类的声音,并且这些声音可以工作。一般来说,这也不是 AudioContext 问题,因为我有以下代码:
Tone.setContext(Howler.ctx);
它确保 Tone 的 AudioContext 通过 Howler 的 AudioContext 进行路由。
有办法让它玩吗?由于 GrainPlayer 独特的属性和功能,我需要继续使用它,因此不幸的是,退出对我来说无法作为解决方案。 我无法从开发人员的角度诊断它,因为我没有 iOS 设备,即使这样,他们也没有办法启动开发人员控制台...... 但它似乎没有破坏代码或任何东西,只是看起来它“忽略”正在播放的声音,然后继续前进。
有问题的声音是这样创建的:
standardChord[0] = new Tone.GrainPlayer('/A.flac').connect(Howler.masterGain);
然后当需要播放它们时:
standardChord[0].start();
正如我所说,它在其他设备上运行良好。
最后,不确定这是否重要,但它是我正在运行的 Meteor 应用程序,捆绑到 Node.js 中进行部署。
I have an application that uses Tone.js, and I use the GrainPlayer object specifically.
It works perfectly fine on different browsers across different OS and devices...
except for iOS. I personally don't have an iOS device, but clients are showing me that iOS isn't playing the audio. It's also not restricted to safari; other browsers on their device also won't play the audio.
I know it's a Tone.js-specific issue here, because I also use Howler.js for a few of the sounds that don't require the Tone GrainPlayer class, and those work. It's also not an AudioContext issue in general, because I have the following code:
Tone.setContext(Howler.ctx);
Which ensures the AudioContext for Tone is routed through the AudioContext for Howler.
Is there a way to get it to play? I need to keep using GrainPlayer because of its unique properties and functions, so switching out will not work for me as a solution unfortunately.
I have no way of diagnosing it from a developer standpoint because again I don't have an iOS device, and even then they don't have a way to pull up a developer console...
But it seems to not break code or anything, just seems like it 'ignores' the sound playing, and moves on.
The sounds in question are created as such:
standardChord[0] = new Tone.GrainPlayer('/A.flac').connect(Howler.masterGain);
And then when they need to be played:
standardChord[0].start();
Which like I said works fine on other devices.
Finally, not sure if this matters or not, but it's a Meteor application I'm running, bundled into a Node.js for deployment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我的项目中,我有一个简单的代码行可以在我的
initAudio()
方法中完成这项工作:synth
只是一个多合成器振荡器。但如果 iPhone 或 iOS 设备静音,则此解决方案不起作用。
附注在 iOS 16.2 上测试
In my project I have a simple line that does the job for me in my
initAudio()
method:synth
is just an polysynth oscillator.But this solution doesn't work if the iPhone or iOS device is muted.
ps. tested on iOS 16.2
我遇到了完全相同的问题,当设备静音时,Tone.js 在较新的 iPhone 和 iPad 上不会播放任何声音。我的解决方案是在用户交互时播放无声 mp3,使用本机 HTML 音频元素来激活声音。我在播放我真正想听的声音之前执行此操作。
您可以让音频元素在用户交互时开始播放。因此,选择音频元素,并在开始播放您真正想听的音频之前调用它的 play() 方法。
我在 LambdaTest 上测试了以下设备(如果您没有 iOS 设备,强烈推荐):
I had the exact same problem, Tone.js doesn't play any sound on the newer iPhones and iPads when the device is muted. My solution was to play a silent mp3 on user interaction, using a native HTML audio element to activate the sound. I do this before playing the sound that I actually want to hear.
You can get the audio element to start playing on user interaction. So select the audio element, and call it's play() method right before starting the audio you actually want to hear.
I tested on the following devices on LambdaTest (highly recommended if you don't own an iOS device):