简体   繁体   English

Safari和移动浏览器上的Soundjs

[英]Soundjs on safari and mobile browsers

Currently my audio won't play on safari and on mobile devices. 目前,我的音频无法在野生动物园和移动设备上播放。 It works fine on a normal pc on FireFox, Chrome and IE 在FireFox,Chrome和IE的普通PC上运行正常

var manifest = [
    { id: "correct", src: 'assets/correct.mp3|assets/correct.ogg' },
    { id: "wrong", src: 'assets/wrong.mp3|assets/wrong.ogg' }
];

var queue = new createjs.LoadQueue();
queue.installPlugin(createjs.Sound);
queue.loadManifest(manifest, true);

And I'm calling the play function like this; 我这样称呼play函数;

createjs.Sound.play("correct");

This function is written inside a function that's called when a user presses a div. 该函数编写在用户按下div时调用的函数内部。

That code looks like it should work. 该代码看起来应该可以工作。 Web Audio is initially muted on iOS devices, but when play is called inside of a user event it unmutes. Web音频最初在iOS设备上被静音,但是在用户事件中调用播放时,音频将取消静音。

There are a couple of possibilities (without seeing the rest of the code): 有两种可能(看不到其余代码):

  1. You are working on iPad 1, which does not support web audio and has html audio disabled by default due to severe limitations. 您正在使用iPad 1,该iPad不支持Web音频,并且由于严重的限制默认情况下禁用html音频。

  2. You are not waiting for the audio to finish loading before calling play: 您无需等待音频完成加载再调用play:

    queue.addEventListener("complete", loadComplete); queue.addEventListener(“ complete”,loadComplete);

  3. The audio file path is incorrect and therefore the load is failing, which you can detect by listening for an error event. 音频文件路径不正确,因此加载失败,可以通过侦听错误事件进行检测。

  4. You are using a non-default encoding for the mp3 files that is not supported by Safari. 您正在使用Safari不支持的mp3文件的非默认编码。 Generally that would break in other browsers as well though. 通常,这也会在其他浏览器中中断。

  5. Safari requires quicktime for html audio to play, so that could be a problem. Safari需要快速时间才能播放html音频,因此可能是个问题。

  6. Using createjs.Sound.registerPlugins, SoundJS is being set to use an unsupported on mobile plugin, such as FlashPlugin. 使用createjs.Sound.registerPlugins,将SoundJS设置为使用不支持的移动插件(例如FlashPlugin)。 You can check your current plugin with: 您可以使用以下方法检查当前的插件:

    createjs.Sound.activePlugin.toString(); createjs.Sound.activePlugin.toString();

You may find the Mobile Safe Tutorial useful. 您可能会发现“ 移动安全教程”很有用。 Hope that helps. 希望能有所帮助。

There is a way to hack it, play an empty mp3 then play the audio. 有一种方法可以破解它,播放一个空的mp3,然后播放音频。

It must load the empty mp3 within mainfest array firstly: 它必须首先在mainfest数组中加载空的mp3:

var manifest = [
    ...
    { id: "empty", src: 'assets/empty.mp3|assets/empty.ogg' }
];

... ...

Before playing the sound, play the empty mp3: 在播放声音之前,播放空的mp3:

createjs.Sound.play("empty");

createjs.Sound.play("correct");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM