jQuery touch move上的Web音频api不工作iOS
Web audio api on jQuery touch move not working iOS
我的代码:
$(document).ready(function(){
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var oscillator = audioCtx.createOscillator();
var gainNode = audioCtx.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);
oscillator.type = 'sine';
gainNode.gain.value = 0;
oscillator.start();
document.addEventListener("touchmove", function(e) {
e.preventDefault();
var touch = e.touches[0];
var x = touch.pageX;
var y = touch.pageY;
x = Math.round(x);
y = Math.round(y);
x = mRound(x, 20);
y = mRound(y, 10);
$("#coords").text(x + ", " + y);
gainNode.gain.value = x / 10;
oscillator.frequency.value = y;
}, false);
});
function mRound(n, m){
if(n > 0)
return Math.ceil(n/m) * m;
else if( n < 0)
return Math.floor(n/m) * m;
else
return m;
}
这在android上的chrome和Firefox中工作,但在iOS上的safari或chrome中没有声音播放。web音频api确实在safari中工作,因为我使用了一个更简单的脚本进行了测试,'touchmove'似乎可以工作,因为坐标出现在# cods中。
谢谢。
我正在处理一个类似的问题。当谈到"自动启动"音频的可能性时,iOS上的WebKit非常挑剔。
在"touchstart"事件上初始化AudioContext在我的iOS 10.1.1的iPhone SE上奏效了:
$(document).ready(function(){
var oscillator, gainNode, audioCtx;
var initOnce = false;
document.addEventListener("touchstart", function(e) {
if (!initOnce){
initOnce = true;
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
oscillator = audioCtx.createOscillator();
gainNode = audioCtx.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);
oscillator.type = 'sine';
gainNode.gain.value = 0;
oscillator.start();
}
});
document.addEventListener("touchmove", function(e) {
e.preventDefault();
var touch = e.touches[0];
var x = touch.pageX;
var y = touch.pageY;
x = Math.round(x);
y = Math.round(y);
x = mRound(x, 20);
y = mRound(y, 10);
$("#coords").text(x + ", " + y);
gainNode.gain.value = x / 10;
oscillator.frequency.value = y;
}, false);
});
function mRound(n, m){
if(n > 0)
return Math.ceil(n/m) * m;
else if( n < 0)
return Math.floor(n/m) * m;
else
return m;
}
相关文章:
- 谷歌地图Api和JS代码不工作
- Backbone/Facebook API未按预期工作
- 在自动完成中使用Google Maps Places API;API不工作
- 给出<选项>标记一个类?API调用不工作
- Youtube Javascript API播放/暂停/停止不工作
- AWS API网关返回400错误请求,但Postman工作正常
- 天气应用 API 不再工作
- $.getJSON 和 google fonts API 停止在 Internet Explorer 中工作,jQuer
- 谷歌地图API停止在Wordpress模板中工作
- Yelp API、OAuth和Angular与JSONP只工作一次
- 噩梦与YouTube API和播放视频工作
- 在iPhone上,Vimeo Javascript API.play()函数没有'播放完视频后才能工作
- 如何让蒸汽 API 工作
- 谷歌图表api工作不正常
- 我不能让Youtube API工作
- 谷歌地图的js api工作在浏览器上,但不是在cordova应用程序
- 谷歌地图API工作时,我打破然后继续,不'否则
- 谷歌地方自动完成api工作无处不在,但子域
- 路由到api工作错误
- 巨人炸弹 API 工作