Small problem with pgSoundLoader and pgSoundControl

Workarounds and usability notes.

Small problem with pgSoundLoader and pgSoundControl

Postby John Robin Dove » Sun Dec 28, 2014 9:53 am

Hi Clifton,

I have found a small problem. At first I thought it was random but in fact it isn't. Here's the scenario: I am working on a musicology program. There are 3 buttons on a page which use pgSoundLoader to play 3 different MP3 files. (They are all disabled once any one of them is clicked and re-enabled when the file stops playing.) They all have stopOnPageNav set to true. There is also a 'stop' button. This uses stopAll to stop whichever file is playing and re-enables the buttons. If you click button A, a file starts playing. If you navigate to another page, the music stops as planned. However sometimes this doesn't happen. If you click button A then click 'stop': no problem but if you then click button B or Button C and then navigate to another page, stopOnPageNav fails to function and the music continues to play. I haven't found a cure as yet.

I also wondered if it were to do with IE but it seems to be the same in all browsers. BTW I was amazed to discover that the Toolbook goToPage action does not function in IE 11! Your version does. Thanks! I thought Toolbook DHTML was designed for IE!
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Small problem with pgSoundLoader and pgSoundControl

Postby John Robin Dove » Sun Dec 28, 2014 10:11 am

I have now fixed by putting in an additional pgSoundControl stopAll on unload page.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Small problem with pgSoundLoader and pgSoundControl

Postby Clifton » Sun Dec 28, 2014 10:16 am

Here is some logic to think about when playing multiple files on a single page:
  • When pgSoundLoader() is used to load and play a sound, the [name] parameter is critical because this is the string that is used to track the properties of the playback sequence.
  • When you use multiple buttons to play files, then it can happen that two audio sequences are mistakenly getting assigned the same string [name] to reference their audio.
  • Then, on page navigation, one of the files MAY continue playing because the other file(s) have become lost or orphaned and the sound controller no longer has a correct reference to the properties that define their playback. If one file continues playing, it is because the sound engine cannot locate the file to manipulate it or to read its properties and stop the playback if that is the intention. So it just lets it play out.
So before we assume a problem exists with the functions themselves, we need to be absolutely sure that the audio files are each playing with their own unique identification string.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Small problem with pgSoundLoader and pgSoundControl

Postby John Robin Dove » Sun Dec 28, 2014 10:25 am

Each button has a unique name and each button is using name of self as the name parameter.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Small problem with pgSoundLoader and pgSoundControl

Postby Clifton » Sun Dec 28, 2014 10:44 am

If that is confirmed, then it is possible that clicking a button twice fires the same audio without stopping the previous audio by the same name. Depending on your logic, it is possible that the onclick event is being fired twice even if the button is clicked once. I've seen that happen with triggers and user events too.

pgSoundLoader() is fully multi-channel capable, so it is always best to use pgSoundControl() to stop an audio by the name you intend to use to play the next sequence. This should prevent ever having multiple audio sequences playing with the same name. Basically, by using stopAll on unload page, you are just cleaning up a problem condition. If that works, fine. But this situation could come back to bite you again unless you isolate exactly why it is happening in the first place.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Small problem with pgSoundLoader and pgSoundControl

Postby John Robin Dove » Sun Dec 28, 2014 10:50 am

Yes but I have tried including 3 separate pgSoundControl stop actions each one with a different name and the problem is still there. It's not a big deal because, as I mentioned earlier, I can solve the problem by adding a pgSoundControl stopAll on unload page but I'd like to understand what is happening.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Small problem with pgSoundLoader and pgSoundControl

Postby Clifton » Sun Dec 28, 2014 11:02 am

Zip up a little test case with files and I will take a look.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Small problem with pgSoundLoader and pgSoundControl

Postby Clifton » Sun Dec 28, 2014 6:05 pm

Thank you for the zip files.
Here is my observation on the reason for the problem:
  • When you click on any button to play a sound, all is fine and the sound is stopped when page navigation occurs during playback. This is the expected behavior.
  • To duplicate the problem: click on a button to begin playing a sound; then click the stop button ... the sound stops. This is also the expected behavior. Next click the same button again to begin playing the same sound; now navigate during playback and the sound will continue playing. This is NOT the expected behavior as the sound should have been stopped on page navigation.
  • WHY? The issue or problem is introduced when you click the stop button on your page. When you use the option to "stopAll", the behavior is to stop all the sounds and move the playhead of each sound to position 0, but it does not UNLOAD them from the browser. This effectively keeps the sound loaded under the previous name that was used to play the sound. Next when the sound is played again under the same name, the sound manager thinks you want to load a NEW sound under the previously used name value. This creates a conflict where two sounds are using the same name string as a reference in the sound manager engine. One of the sounds now becomes orphaned without a reference in the sound manager. On page navigation, the orphaned sound will end up continuing to play.
  • SOLUTION 1: On each button that begins playing a sound, you should call pgSoundControl() to check the status of the sound. If the status is 0 or null, then call pgSoundLoader() to load (or initialize) and play the sound. If the the result is > 0 then call pgSoundControl() with the property "play" to begin playing it again.
  • SOLUTION 2: Adjust your stop button to unload or destroy the currently playing sound rather than using "stopAll".
Essentially, when managing multiple sounds on a single page, you need to unload/destroy previous ones before you can reuse their names. All of this is irrespective of the actual file itself because the PowerPac sound engine can load the same audio file multiple times under different names. As soon as you reuse a name that has not been specifically unloaded/destroyed, you get a reference error and lose the ability to control the sound on page navigation.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Small problem with pgSoundLoader and pgSoundControl

Postby John Robin Dove » Mon Dec 29, 2014 9:06 am

Hi Clifton,

Many thanks for your detailed reply.

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Small problem with pgSoundLoader and pgSoundControl

Postby Clifton » Mon Dec 29, 2014 4:39 pm

Well, it seems I've blundered a bit on this. While my explanation may be fine in most cases, in the instance of your logic, this whole thing should have worked. After further investigation, I noticed that when multiple sounds are loaded and stopped on a single page that during page navigation all but one sound is destroyed even if that sound is marked stopOnPageNav = true. If that sound is currently playing, then it will continue playing until it finishes on the next page.

The problem occurs in the PowerPac with an array sizing issue during the method used to parse all the loaded sounds. I've fixed this and your original logic should now work fine. The next version of the PowerPac will contain the patch for this problem.

Thank you for providing a test case of this for us!!
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron