Phonegap lowlatencyaudio插件音乐仅在Android中太嘈杂

时间:2014-07-09 15:50:49

标签: cordova

我正在使用Phonegap构建为iOS和Android平台开发应用程序。我想要多个音乐文件[.wav]并且可以一次播放。 因此,我使用了LatencyAudio插件from here

这是来自jquery文件的代码:

 var click_sound = "sounds/sound1a.wav";
 var music_mp3 = "sounds/gameover.wav";

document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady () {
                                preloadFX: function ( id, assetPath, success, fail) {
                                    return PhoneGap.exec(success,fail,"PGLowLatencyAudio", "preloadFX", [id, assetPath]);
                                },

                                preloadAudio: function ( id, assetPath, voices, success, fail) {
                                    return PhoneGap.exec(success, fail, "PGLowLatencyAudio", "preloadAudio", [id, assetPath, voices]);
                                },

                                play: function (id, success, fail) {
                                    return PhoneGap.exec(success, fail, "PGLowLatencyAudio", "play", [id]);
                                },

                                stop: function (id, success, fail) {
                                    return PhoneGap.exec(success, fail, "PGLowLatencyAudio", "stop", [id]);
                                },

                                loop: function (id, success, fail) {
                                    return PhoneGap.exec(success, fail, "PGLowLatencyAudio", "loop", [id]);
                                },

                                unload: function (id, success, fail) {
                                    return PhoneGap.exec(success, fail, "PGLowLatencyAudio", "unload", [id]);
                                }
  });

    PGLowLatencyAudio.preloadAudio( music_mp3 , music_mp3, 1, function(msg){ //Success}, function(msg){ //Error Call back});
    PGLowLatencyAudio.preloadAudio( click_sound , click_sound , 1, function(msg){ //Success}, function(msg){ //Error Call back});   

     PGLowLatencyAudio.play(music_mp3);
     PGLowLatencyAudio.play(click_sound );

这在iOS和Android中完美运行,仅在Android music_mp3文件中声音过于嘈杂且响亮。我不明白需要修复什么?对此有何解决方案?

1 个答案:

答案 0 :(得分:1)

我们需要将回调preloadFX替换为preloadAudio。因为,默认情况下,有一个实例将被停止&点击播放时重新启动。 因此,将行更新为:

    PGLowLatencyAudio.preloadFX( music_mp3 , music_mp3, 1, function(msg){ //Success}, function(msg){ //Error Call back});
    PGLowLatencyAudio.preloadFX( click_sound , click_sound , 1, function(msg){ //Success}, function(msg){ //Error Call back});  

请仔细阅读完整的文档。