8.7 C
Canberra
Monday, October 27, 2025

javascript – Audio Context in iOS will not resume from droop


I’ve a web site that performs audio. It’s most frequently run within a WebView in an iOS app, although it may be accessed instantly. The audio is being performed utilizing an AudioContext. When the gadget goes to sleep, or the display screen is put to sleep, the AudioContext will likely be suspended. I’m listening to the statechange occasion and if the audio state adjustments to suspended or interrupted I’ll show a pause indicator when the consumer comes again to the app. Clicking the pause indicator triggers the next code:

async operate resumeAudio() {
    if (context.state === SUSPENDED || context.state === INTERRUPTED) {
        strive {
            console.log(`Audio context state is ${context.state}. Making an attempt to renew audio context.`);
            await context.resume();
            console.log(`Audio context resumed. State is now ${context.state}.`);
        } catch (e) {
            console.error('Error resuming audio context: ', e);
        }
    }
}

Typically when the context is suspended the resume name will work, generally it will not. When it fails to work the await context.resume() name by no means resolves.

Is there any clarification for why it will get caught in droop? The one causes I’ve appear up to now cope with needing the context.resume() name to be a part of a consumer enter, which is how I’m doing it.


Edit: Realized simply after posting that I forgot to await the context.resume(). I edited the operate to be async and am now awaiting the resume.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles