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

media-source-buffer example doesn't work in Safari #55

Closed
nwang92 opened this issue Dec 24, 2021 · 2 comments
Closed

media-source-buffer example doesn't work in Safari #55

nwang92 opened this issue Dec 24, 2021 · 2 comments

Comments

@nwang92
Copy link

nwang92 commented Dec 24, 2021

Live example: https://mdn.github.io/webaudio-examples/media-source-buffer/

I found this example from the docs here: https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaElementSource

With Safari (Version 15.2 build 17612.3.6.1.6), this example using createMediaElementSource() doesn't output any audio. It works fine in Chrome (96.0.4664.110) and Firefox (95.0.2).

@mart-jansink
Copy link

I just ran into the same problem. Luckily, a remark on a older WebKit issue related to createMediaElementSource() (https://bugs.webkit.org/show_bug.cgi?id=211394#c37) gave the solution: the new AudioContext() should be created after e.g. a click event since the play event apparently doesn't count as user input.

@nwang92
Copy link
Author

nwang92 commented Jan 3, 2022

I see, that makes sense. For others hitting this issue, here's some code I added to make it work.

First add a button:

<body>
    <h1>createMediaElementSource example</h1>
    <button>Click me</button>
    ...

Then move the entirety of the existing play event handler into a click event handler of the button. Not super intuitive, but it does make the example work on Safari now:

const button = document.querySelector('button');
button.addEventListener('click', event => {
  audioCtx = new AudioContext();
  // Create a MediaElementAudioSourceNode
  // Feed the HTMLMediaElement into it
  let source = audioCtx.createMediaElementSource(myAudio);

  // Create a gain node
  let gainNode = audioCtx.createGain();
  ...

@nwang92 nwang92 closed this as completed Jan 3, 2022
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

No branches or pull requests

2 participants