簡體   English   中英

簡單的振盪器,但IOS上的網絡音頻API沒有聲音

[英]Simple oscillator, but no sound with web audio API on IOS

這是一個非常簡單的例子,我試圖在Chrome上運行iphone。 其他網絡音頻API示例像這樣一個http://alxgbsn.co.uk/wavepad/工作,但不是我的:(

<!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>

知道什么是錯的嗎?

編輯

總結答案:

  1. 響應用戶交互啟動音頻
  2. 檢查靜音開關是否關閉

iOS只會讓您通過用戶操作開始使用Web Audio API播放聲音。

嘗試將該代碼放在某種事件處理程序中。

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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM