admin管理员组

文章数量:1277271

Here is a super simple example that I am trying to run on an iphone in chrome. Other web audio API examples like this one / work, but not mine :(

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>

<body>

  <script>
    var audioContext, osc
    audioContext = new (window.AudioContext || window.webkitAudioContext);
    osc = audioContext.createOscillator()

    osc.connect(audioContext.destination)
    if (osc.noteOn) osc.start = osc.noteOn
    osc.start(0)
    osc.frequency.value = 440
  </script>

</body>

</html>

Any idea what's wrong?

EDIT

To summarize the answer :

  1. start the audio in response to user interaction
  2. check that mute switch is off

Here is a super simple example that I am trying to run on an iphone in chrome. Other web audio API examples like this one http://alxgbsn.co.uk/wavepad/ work, but not mine :(

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>

<body>

  <script>
    var audioContext, osc
    audioContext = new (window.AudioContext || window.webkitAudioContext);
    osc = audioContext.createOscillator()

    osc.connect(audioContext.destination)
    if (osc.noteOn) osc.start = osc.noteOn
    osc.start(0)
    osc.frequency.value = 440
  </script>

</body>

</html>

Any idea what's wrong?

EDIT

To summarize the answer :

  1. start the audio in response to user interaction
  2. check that mute switch is off
Share Improve this question edited Feb 1, 2014 at 8:50 sebpiq asked Jan 28, 2014 at 18:07 sebpiqsebpiq 7,81210 gold badges55 silver badges72 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 12

iOS will only let you start playing sound with the Web Audio API as a result of a user action.

Try putting that code inside of some kind of event handler.

var elem = document.getElementById('play'),
  audioContext = new (window.AudioContext || window.webkitAudioContext),
  osc = audioContext.createOscillator();

osc.connect(audioContext.destination);
if (osc.noteOn) osc.start = osc.noteOn
osc.frequency.value = 440;

play.addEventListener('click', function() {
  osc.start(0);
}, false);

本文标签: javascriptSimple oscillatorbut no sound with web audio API on IOSStack Overflow