package  classes.gustavo.midia.player
{
	import flash.events.*;
	import flash.media.*;
	import flash.net.*;
	

	public class Som extends Sound
	{
		
		private var chanel					:SoundChannel;
		private var porcento				:int;
		private var posicaoMusica			:Number = 0;
		private var som						:Sound;

		private var volume					:Volume;
		
		
		private var rolando					:Boolean = true;

		public function Som() 
		{
		
			

			
		}
		
		public function loadSound(url:String):void
		{
			if (url != null)
			{
				som = new Sound();
				som.load(new URLRequest(url));
				som.addEventListener(Event.COMPLETE, completeSound);
				som.addEventListener(ProgressEvent.PROGRESS, progressSound);
			}
			else
			throw new Error("URL SOUND NULA");
			
			return void;
			
		}
		
		private function progressSound(e:ProgressEvent):void 
		{
			porcento = Math.round( (e.bytesLoaded / e.bytesTotal)*100 );
		}
		
		private function completeSound(e:Event):void 
		{
			
			playSound();
			
			return void;
		}
		
		public function playSound():void
		{
			
			chanel 			 = som.play(posicaoMusica);
			volume.setChanel = getChanel;
			
			return void;
		}
		
		public function stopSound():void
		{
			
			posicaoMusica	  = chanel.position;
			chanel.stop();
			
			return void;
		}
		
		public function reset():void
		{
			if (som)
			{
	
				this.removeEventListener(Event.COMPLETE, completeSound);
				this.removeEventListener(ProgressEvent.PROGRESS, progressSound);
				stopSound();
				posicaoMusica = 0;

			}
		}
		
		private function get getChanel():SoundChannel
		{
		    return chanel;	
		}
		
		public function set setVolume(_volume:Volume):void
		{
			
			volume = _volume;
			
			return void;
		}
			
			
	}//end class

}