Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close and recreate audiocontext for every play #674

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion frontend/src/util/webAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ export const stopBuffer = () => {

// play buffer by section.id
export const playBuffer = (id) => {
// temporary solution for ios17
// https://devcodef1.com/news/1068842/fixing-ios-17-web-audio-issue
audioContext.close();
Copy link
Contributor

@drikusroor drikusroor Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this throw an error if audioContext isn't (yet) defined, or is that impossible to happen? It is is possible to happen, perhaps we can play it defensively, e.g.:

    if (audioContext) {
        audioContext.close();
        audioContext = new (window.AudioContext || window.webkitAudioContext)();
    }
    
    // and continue

audioContext = new (window.AudioContext || window.webkitAudioContext)();

source = audioContext.createBufferSource();
source.buffer = buffers[id];
source.connect(audioContext.destination);
Expand All @@ -115,10 +120,15 @@ export const playBuffer = (id) => {

// Play buffer from given time
export const playBufferFrom = (id, time) => {
// temporary solution for ios17
// https://devcodef1.com/news/1068842/fixing-ios-17-web-audio-issue
audioContext.close();
audioContext = new (window.AudioContext || window.webkitAudioContext)();

source = audioContext.createBufferSource();
source.buffer = buffers[id];
source.connect(audioContext.destination);
source.start(0, time);
source.start(0, time);
}

// Suspend webaudio (frees up resources)
Expand Down
Loading