How to loop a audio in phonegap?

后端 未结 2 1322
梦毁少年i
梦毁少年i 2021-01-12 14:27

I\'m using phonegap 2.2.0. I tried some code to loop the audio for playing without interruption but it is not working on my android device. It plays only on

相关标签:
2条回答
  • 2021-01-12 14:39

    Looping is not supported for Android yet in Phonegap - so numberOfLoops does nothing except on iOS devices.

    0 讨论(0)
  • 2021-01-12 14:41

    Listen to status change and start paying on MEDIA_STOPPED. If you want the user to stop the sound, use snd.pause() and not snd.stop()

    This worked for me:

        document.addEventListener("deviceready", onDeviceReady, false);
    
        var getPhoneGapPath = function() {
            var path = window.location.pathname;
            path = path.substr( path, path.length - 10 );
            return path;
        };
    
        var snd = null;
    
        function onDeviceReady(){
            snd = new Media( getPhoneGapPath() + "sound/funk_game_loop.mp3", onSuccess, onError, onStatus);
            snd.play();
        }
    
        // onSuccess Callback
        function onSuccess() {
        }
        // onError Callback 
        function onError(error) {
        }
        // onStatus Callback 
        function onStatus(status) {
            if( status==Media.MEDIA_STOPPED ) {
                snd.play();
            }
        }
    
    0 讨论(0)
提交回复
热议问题