简体   繁体   English

音频无法在 iOS Cordova Phonegap 应用中播放

[英]Audio won't play in iOS Cordova Phonegap app

I am creating a cross platform Cordova Phonegap soundboard app.我正在创建一个跨平台的 Cordova Phonegap 音板应用程序。 Everything works fine on the android version but on the iOS version the sound refuses to play.在 android 版本上一切正常,但在 iOS 版本上声音拒绝播放。 I use SoundJS and PreloadJS to load and play the audio.我使用 SoundJS 和 PreloadJS 来加载和播放音频。 I used the Phonegap remote debugging server and found out that iOS recognizes the audio as something called "application/octet stream" (see pictures).我使用了 Phonegap 远程调试服务器,发现 iOS 将音频识别为所谓的“应用程序/八位字节流”(见图)。

Everything is fine on Android在 Android 上一切都很好

Android安卓

But I get this on iOS但我在 iOS 上得到了这个

iOS IOS

I load the audio like this:我像这样加载音频:

var sound3= "sound3";
    createjs.Sound.registerSound("audio/anybody.mp3", sound3);

    $(function(){
    $( "#sound3" ).bind( "tap", tapHandler ) 

    function tapHandler( event ){

        sound3.play();
    }
});

Can somebody help me out?有人可以帮我吗?

I had a similar issue on one of my Cordova projects.我在我的 Cordova 项目之一上遇到了类似的问题。

First possible reason:第一个可能的原因:

This appears because of different browsers(web views) can play just some specific types.这是因为不同的浏览器(网络视图)只能播放某些特定类型。 You need to have sound in different formats, such as mp3 or ogg and before playing sound you need to detect maintained format.您需要具有不同格式的声音,例如mp3ogg并且在播放声音之前您需要检测保持的格式。 Look at this documentation Audio canPlayType and make checks before playing查看此文档Audio canPlayType并在播放前进行检查

Second possible reason : File system issues.第二个可能的原因: 文件系统问题。 iOS resources path is not equal to Android resources path and before sound initialization you need to build a platform-specific path to your local resources iOS资源路径不等于Android资源路径,在声音初始化之前,您需要为本地资源构建特定于平台的路径

And also try to play native browser audio instead of using createjs , like this:并且还尝试播放本地浏览器audio而不是使用createjs ,如下所示:

var sound3 = document.createElement('audio');

sound3.src = "audio/anybody.mp3";

function tapHandler( event ){
    sound3.play();
}

$(function(){
  $( "#sound3" ).bind( "tap", tapHandler ) 
});

Did you try using an m4a audio file (aac)?您是否尝试使用 m4a 音频文件 (aac)? This seems to be the format Apple prefers.这似乎是 Apple 喜欢的格式。 Also make sure there is always only one sound playing at the time as iOS can only handle one audio playback at a time.还要确保每次只播放一种声音,因为 iOS 一次只能处理一种音频播放。

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

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