Start a new topic
Solved

AR,Sound gets destroyed immedidately

I needed help. I do not understand why new AR,sound gets destroyed by itself. 

I have not even start play thus it can't due to streaming and "auto" destroy.


I was initializing 

this.bgm = new AR.Sound("assets/sfx/bgm1.mp3", {

   onError : function(){

    return; 

   },

  });


and I cannot play it later because it was destroyed. If I have this line

this.bgm.play(-1) right immediately after the initialization, it will play. However when I have a stop function and tries to do this.bgm.stop() it shows up {"destroyed":true}.

But the sound kept on playing and I cannot stop it.





Hello Ren,

Did you refer to the documentation here in order to see how to define the Sound class?

Thanks
Eva

 

I'm not trying to be funny here but your reply confused me even further. Is my code this.bgm = new AR.Sound("assets/sfx/bgm1.mp3", { onError : function(){ return; }, }); Is there any different your documentation in terms of how the class should be define? Also adding onLoad does nothing. It was never called.
Hi Ren,

This is exactly how you need to implement it and you need to call the load() function so that the audio file will start.

this.sirenSound = new AR.Sound("assets/song.mp3", {
            onError : function(){
                alert(errorMessage);
            }
        });
        this.sirenSound.load();

 

Thanks

Eva

 

Hi, We done similar to this.sirenSound.load(). onloaded obviously is being called. Then when we did this.sirenSound.play(), it returns error and you know what? We check the state + destroyed and even do this alert(JASON.stringify(this.sirenSound)): This is the result {destroy: true}. Thus the thread titled Sound Destroyed immediately.
I think I need to clarify further, if I play the file immediately during the onload being called. It will play. onLoad: function(){ this.sirenSound.play();} There is no problem in playing the moment within onload callback. Here is the confusing part, in reality we do not play the sound immediately. I can only assume the onload is a way to tell me the file is loaded and I can call off preloading and move into the app. So if I call this.sirenSound.play outside of onload but I'm a different stage later in the app, I can't play it because the it is destroyed. It is destroyed even before I play it.
Hello Ren,

You can play the sound file whenever you want. You can for example put a button and play the sound file whenever the user clicks this button. But what you need to keep in mind is that you need to execute the sound.play() when the file is in a state LOADED or PAUSED or INITIALIZED. Otherwise, it will have no effect.

Thanks
Eva

 

Hi Eva,

We created a fresh clean js and did exactly the same thing except this time is step by step showing console log starting from load() first, then check onLoad, then within onLoad set timeout 10sec later to play(). And when it gets play, we set another timeout 10 sec to stop and another timeout 10 sec to play it back.

The above steps work accordingly now. The sound file is LOADED and we can play, pause and stop it any time. It seems to be working and the AR.sound object is not detroyed.

Thank you for your patience.


 

Hi Ren,

I am glad that it worked out in the end. I am aware that the documentation might have not been as clear so we will update it for our next release.

Thanks
Eva

 

Login or Signup to post a comment