Start a new topic

OnClick stop the sound if already playing

OnClick stop the sound if already playing


Thanks Martin.

The marker is responding to the click by checking the state.

Regards,

markerclick_musicfn = function(marker)

{  return function() {

    try {

                     //sound.onFinishedPlaying = function(){alert("Playing finished");};

    if(! sound){

        sound = new AR.Sound("assets/music.mp3", {

                     onLoaded : function(){ //alert("playing");

                     sound.play();

                             },

                     onError : function(){

                     // alert the user that the sound file could not be loaded

                     alert("errrrror");

                     },

                     });

        sound.load();

        }

        else

        {

            //alert(sound.state);

            if (sound.state ==  3)

                sound.pause();

            else

                sound.resume();

        }

        

    }

    

    catch (err) {

        alert(err);

    }

    

}

}

Hi,

You can check the status of the sound file using the state property: http://www.wikitude.com/external/doc/documentation/latest/Reference/JavaScript%20Reference/classes/Sound.html#property_state

Best,

Martin

Hi,

I have created a marker that will play music upon click. I would like the music to pause on the second click and so on.

How to check the state of the sound if it's playing or not and do the pause accordingly?

Thanks

 
Login or Signup to post a comment