1

我有一个启动并运行 soundmanager2 的非常简单的示例,它不会在 IOS 中触发:

    $(document).ready(function(){

    var introSound;

    setupSoundManager();

    function setupSoundManager(){
      soundManager.setup({

        // where to find the SWF files, if needed
        url: 'swf/',
        preferFlash: false,
        onready: function() {
          // SM2 has loaded, API ready to use e.g., createSound() etc.
          createSound();
        },

        ontimeout: function() {
          // Uh-oh. SWF missing, Flash blocked or other issue
          console.log('cant setup');
        }

      });
    }

    function createSound(){
      introSound = soundManager.createSound({
       url: 'intro-with-drums.mp3',
       // callback for when the sound has loaded
       onload: function() {
         soundManager._writeDebug(this.id + ' loaded');
         enablePlay(this);
       }
      }).load();
    }


    function enablePlay(thisSound){
      $('#sound').on('click',function(){
        introSound.play();
      });
    }



  });

桌面在加载时会经历这个阶段:

sound0: 使用 HTML5 soundmanager2.js:1190 sound0: 加载 (intro-with-drums.mp3) soundmanager2.js:1190 sound0: loadstart soundmanager2.js:1190 sound0: 暂停 sound0: 加载元数据 soundmanager2.js:1190 sound0: 加载数据 soundmanager2。 js:1190 sound0: 可以播放 soundmanager2.js:1190 sound0: onload() soundmanager2.js:1188 sound0 已加载

而iOS只做:

sound0: 使用 HTML5 soundmanager2.js:1190 sound0: 加载 (intro-with-drums.mp3) soundmanager2.js:1190 sound0: loadstart soundmanager2.js:1190 sound0: 暂停

我如何让它在 iOS 上运行?

4

1 回答 1

1

大多数移动浏览器将拒绝加载/缓冲任何没有直接物理交互的音频/视频。这意味着您无法在页面加载或任何异步函数(如 setTimeout)中触发初始播放/预加载。由于这个限制introSound永远不会加载,这意味着enablePlay永远不会被调用,这意味着您的#sound元素永远不会添加事件侦听器。

于 2013-07-26T21:37:19.143 回答