Pausing and resuming playback

The SoundFacade.play() method shown previously accepts a pos parameter corresponding to a starting position in the sound data. If the pos value is zero, the sound starts playing from the beginning.

The SoundFacade.stop() method also accepts a pos parameter as shown here:

public function stop(pos:int = 0):void
{
    if (this.isPlaying)
    {
        this.pausePosition = pos;
        this.sc.stop();
        this.playTimer.stop();
        this.isPlaying = false;
    }    
}

Whenever the SoundFacade.stop() method is called, it sets the pausePosition property so that the application knows where to position the playhead if the user wants to resume playback of the same sound.

The SoundFacade.pause() and SoundFacade.resume() methods shown below invoke the SoundFacade.stop() and SoundFacade.play() methods respectively, passing a pos parameter value each time.

public function pause():void
{
    stop(this.sc.position);
}

public function resume():void
{
    play(this.pausePosition);
}

The pause() method passes the current SoundChannel.position value to the play() method, which stores that value in the pausePosition property. The resume() method starts playing the same sound again using the pausePosition value as the starting point.


Flash CS3