«

»

Music class

Music class idea came up when I was creating i2FlashMP3. I want to make a class that can play and load sound, set volume and pan of a sound.

Loading, playing and, set sound volume

package
{
	import com.irzal.media.Music;
	import flash.display.Sprite;

	public class MusicExample extends Sprite
	{
		private var music:Music = new Music();

		public function MusicExample()
		{
			music.start("/path/yourMP3.mp3");
			music.volume = 0.5;
		}
	}
}

With Music class you can also get sound length, sound position, sound load progress and sound buffering progress

package
{
	import com.irzal.media.Music;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	public class MusicExample extends Sprite
	{
		private var music:Music = new Music();
		private var sndPosition:TextField = new TextField();
		private var sndLength:TextField = new TextField();
		private var sndBuffer:TextField = new TextField();
		private var sndError:TextField = new TextField();

		public function MusicExample()
		{
			sndPosition.autoSize = TextFieldAutoSize.LEFT;

			sndLength.autoSize = TextFieldAutoSize.LEFT;
			sndLength.y = 20;

			sndError.autoSize = TextFieldAutoSize.LEFT;
			sndError.y = 40;

			sndBuffer.autoSize = TextFieldAutoSize.LEFT;
			sndBuffer.y = 60;
			//add text field
			addChild(sndPosition);
			addChild(sndLength);
			addChild(sndBuffer);
			addChild(sndBuffer);
			//load and play
			music.start("/path/yourMP3.mp3");
			//display buffer progress
			music.displayBuffering(sndBuffer);
			//display sound position
			music.displayPosition(sndPosition);
			//display sound length
			music.displayLength(sndLength);
			//display error message
			music.displayError(sndError);
		}
	}
}

documentation
Music class download

Leave a Reply

Your email address will not be published.

*