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

fix(audiocontext): works on both Safari and Chrome #22

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dselman
Copy link

@dselman dselman commented Dec 18, 2024

Fix for issue: #21

I'm not sure why the original code was so complex, but this simplified version seems to work on both Safari and Chrome on Mac OS.

Possibly related to: https://developer.chrome.com/blog/autoplay/#webaudio

const map: Map<string, AudioContext> = new Map();

export async function audioContext(options?: GetAudioContextOptions,) : Promise<AudioContext>  {
    if (options?.id && map.has(options.id)) {
      const ctx = map.get(options.id);
      if (ctx) {
        return ctx;
      }
    }

    const ctx = new AudioContext(options);
    if (options?.id) {
      map.set(options.id, ctx);
    }
    return ctx;
}

Copy link

google-cla bot commented Dec 18, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@dselman
Copy link
Author

dselman commented Dec 18, 2024

Yes, this is now broken on Chrome... More investigation needed.

@dselman dselman marked this pull request as draft December 18, 2024 16:20
@dselman
Copy link
Author

dselman commented Dec 18, 2024

Interesting thread: https://stackoverflow.com/a/74495761

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant