iOS6/7使用Web音频API停止声音进入背景 [英] iOS6/7 stop sound going to background using web audio API

查看:157
本文介绍了iOS6/7使用Web音频API停止声音进入背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您在iPhone或iPad上进入后台并持续播放声音时,有多种解决方案,其中大多数用于 ,这是一个当然的概念. 页面可见性API 仅在您更改标签页后才能在iOS7中使用,但如果您不使用后台,则不会,在iOS6中根本不会.

There are different solutions for the issue when you go to the background in the iPhone or iPad and the sound continuous playing, the most of them for the HMTL5 audio tag, but are not relevant if you are using Web Audio API because there are not an event like "timeupdate" and is a different concept of course. The Page Visibility API works in iOS7 only if you change of tab, but doesn't if you go to the background, in iOS6 not at all.

如果您在iOS6或iOS7中进入后台,有人知道使用 Web音频API 停止/静音的任何方法吗?

Someone knows any way to stop/mute a sound using Web Audio API if you go to the background in iOS6 or iOS7?

推荐答案

要检测野生动物园何时进入后台,您可以使用窗口的事件pageshowpagehide(但是您已经发现了).

To detect when safari is going background, you can use window's events called pageshow and pagehide (but this you already found out).

document.addEventListener('pageshow',function(){
    // Do something here
}, false);

document.addEventListener('pagehide',function(){
    // Do something here
}, false);

您还可以使用 PageVisibility API (

You can also use the PageVisibility API (available since iOS7) to check if the tab has changed.

document.addEventListener('visibilitychange', function(){
    if (document.hidden) {
        // Tab out of focus
    }
    else {
        // Tab on focus
    }
},false);

请注意,此代码自iOS7起就可以在野生动物园中使用,但是某些浏览器需要前缀.

Note that this code should work on safari since iOS7, but some browsers needs prefixes.

这篇关于iOS6/7使用Web音频API停止声音进入背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆