tweening volume on an flv playback in AS3.

16 10 2007

We now know how to control playback of an flv file and read the cue points (Refer my previous post) in AS3. The next step for me is to be able to tween the volume down. Since NetStream.SoundTransform.volume is a read-only value (at least to me), I couldn’t use Tweener.addTween directly on the SoundTransform. Following is a shortcut I found to do the tweening without creating “special features” for Tweener. Check out the “fadeOut” method.

package{

	import com.caurina.transitions.Tweener;
	import flash.display.Sprite;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.media.SoundTransform;

        public class StreamingFlv extends Sprite{

               protected var connection:NetConnection;
               protected var nStream:NetStream;

               public function StreamingFlvAudio(_url:String ){
                        //code  to start flv playback
               }
               
		public function fadeOut():void{
			var sTrans:SoundTransform = new SoundTransform();
			sTrans.volume=nStream.soundTransform.volume;
			Tweener.addTween(sTrans, {volume:0, time:2, transition:"easeInOutQuad",onUpdate:function():void{nStream.soundTransform = sTrans;},onComplete:function():void{nStream.close();connection.close();}});
                }
        }
}

It works perfectly. Please leave a message if you know have better ways to achieve it. 🙂

Advertisements

Actions

Information

One response

16 10 2009
Tyrone Neill

Thanks I found this useful though its a bit excessive to recreate a new Sound Transform each time, would it not be easier to have a private SoundTransform and use it for each time you fadeOut.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: