简体   繁体   中英

PhoneGap Android LowLatencyAudio plugin doesn't work

I'm building a mobile game with HTML5 and Javascript, for Android devices.

Android doesn't support HTML5 Audio, that's why i've choose to use a phonegap plugin : https://github.com/phonegap/phonegap-plugins/tree/master/Android/LowLatencyAudio

My structure is very simple, i've got 3 objects.

  • game, which is my main object.
  • animation, which is my object where are all my sprites animations.
  • sound, which all my sound are played, looped or stopped.

Here, my index.html file :

<!DOCTYPE HTML>
<html>
    <head>
    <title>Test</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
    <meta charset="UTF-8" />
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
    <script type="text/javascript" charset="UTF-8" src="cordova.js"></script>
    <script type="text/javascript" charset="UTF-8" src="PGLowLatencyAudio.js"></script>
    <script type="text/javascript" charset="UTF-8" src="assets/js/src/pixi.js"></script>
    <script type="text/javascript" charset="UTF-8" src="assets/js/game.js"></script>
    <script type="text/javascript" charset="UTF-8" src="assets/js/sound.js"></script>
    <script type="text/javascript" charset="UTF-8" src="assets/js/animation.js"></script>
    <script type="text/javascript" charset="UTF-8">
        function onDeviceReady(){
            PGLowLatencyAudio.preloadFX('drum','assets/son/drum/drumPiste1.mp3', game.sound.successHandler, game.sound.errorHandler);
        };
        function onBodyLoad(){
            document.addEventListener("deviceready",onDeviceReady,false);
        };
    </script>
</head>
<body onload="onBodyLoad()">
    <div id="wrapper"></div>
    <script type="text/javascript" charset="UTF-8">
        game.init();
        game.sound.init();
        game.animation.init();
    </script>
</body>

I'm using the PGLowLatencyAudio.preloadFX function of the plugin, to preload my mp3 file.

After, I call my init function of my object sound, which is like that :

game.sound = {

    init: function(){
        soundsArray = [];
        game.sound.playSound();
    },

    successHandler: function(result){
        alert(result);
    },

    errorHandler: function(error){
        alert(error);
    },

    playSound: function(){
        PGLowLatencyAudio.play('drum', game.sound.successHandler, game.sound.errorHandler);
    },

};

In my init function, i call my playSound function, to play the sound i've previously preload.

It try to play sound before preload, but i don't understand why.

Error message is : A reference does not exist for the specified audio id .

Here's the link , which i followed for a similar project earlier. It has the solution to the problem !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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