3 Replies Latest reply: Apr 30, 2012 7:28 AM by kglad RSS

    Occasional no sound when trying to play sound.

    DKostrzewa

      Hi all,

       

      I am having a problem where sometimes there is no sound when I try to play an mp3 file from within a SWF I have created in CS3 Professional.

       

      By sometimes I mean 1 time out of 10, sometimes more or less frequently.

       

      I have a button btnPlay whose onClick event starts the sound playing. It works most of the time, but occasionally there is no sound at all. Refreshing the page and reloading the flash does help sometimes but not always.

       

      Due to the nature of the application we don't allow users to replay the sound nor to refresh the page so it is very important to play the sound properly every time.

       

      The code is below:

       

      var sound:Sound = null;
      
      btnPlay.enabled=false;
      btnPlay._alpha=25;
      
      sound=new Sound(this);
      sound.onLoad=function(success){
        if (success) {
          sound.setVolume(100);
          btnPlay.enabled=true;
          btnPlay._alpha=100;
        } 
        else {
          btnPlay._alpha = 0;
        }
      }
      
      sound.onSoundComplete=function(){
        if(allowReplay){
          btnPlay.enabled=true;
          btnPlay._alpha=100;
          sound.stop();
         }
      }
      
      btnPlay.onPress=function(){
        sound.start(0, 1);
        btnPlay.enabled=false;
        btnPlay._alpha=25;
      }
      
      Stage.addListener(this);
      Stage.align=("TL");
      function onResize(){
        btnPlay._x=(Stage.width/2)-(btnPlay._width/2);
      }
      onResize();
      sound.loadSound(MediaUrl, false);
      

       

      Also because we’re greying out the button when play starts and showing it normally when the sound is complete, we can actually see how long the sound is supposed to be playing for, even if we hear no sound. In these cases it still shows greyed out for the right amount of time we’re expecting that sound file to play for.

       

      I’ve googled but can't find anything that says there is a known problem, nor can I see any problem in my code since the sound is successfully requested and loaded every time – i.e. the sound.onLoad event handler is always successful.

       

      We use this component in a couple of SWFs and on a set of different web pages and the problem still occurs.

       

      Does anyone has any suggestions or could give me directions how to solve this problem?