admin管理员组文章数量:1335386
I have a website that plays audio. It is most often run inside of a WebView in an iOS app, though it can be accessed directly. The audio is being played using an AudioContext. When the device goes to sleep, or the screen is put to sleep, the AudioContext will be suspended. I am listening to the statechange
event and if the audio state changes to suspended
or interrupted
I will display a pause indicator when the user comes back to the app. Clicking the pause indicator triggers the following code:
async function resumeAudio() {
if (context.state === SUSPENDED || context.state === INTERRUPTED) {
try {
console.log(`Audio context state is ${context.state}. Attempting to resume audio context.`);
await context.resume();
console.log(`Audio context resumed. State is now ${context.state}.`);
} catch (e) {
console.error('Error resuming audio context: ', e);
}
}
}
Sometimes when the context is suspended the resume call will work, sometimes it won't. When it fails to work the await context.resume()
call never resolves.
Is there any explanation for why it gets stuck in suspend? The only reasons I've seem so far deal with needing the context.resume()
call to be part of a user input, which is how I am doing it.
Edit: Realized just after posting that I fot to await
the context.resume()
. I edited the function to be async and am now awaiting the resume.
本文标签: javascriptAudio Context in iOS won39t resume from suspendStack Overflow
版权声明:本文标题:javascript - Audio Context in iOS won't resume from suspend - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742389501a2465704.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论