播放本地MP3 (一)

package {
	import flash.display.Sprite;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.events.MouseEvent;
	import flash.text.TextFieldAutoSize;

	public class SoundChannel_stopExample extends Sprite {
		private var snd:Sound = new Sound();
		private var channel:SoundChannel = new SoundChannel();
		private var button:TextField = new TextField();

		public function SoundChannel_stopExample() {
			var req:URLRequest=new URLRequest("陈奕迅 - 一丝不挂.mp3");
			snd.load(req);

			button.x=10;
			button.y=10;
			button.text="PLAY";
			button.border=true;
			button.background=true;
			button.selectable=false;
			button.autoSize=TextFieldAutoSize.CENTER;

			button.addEventListener(MouseEvent.CLICK, clickHandler);

			this.addChild(button);
		}

		private function clickHandler(e:MouseEvent):void {
			var pausePosition:int=channel.position;

			if (button.text=="PLAY") {
				channel=snd.play(pausePosition);
				button.text="PAUSE";
			} else {
				channel.stop();
				button.text="PLAY";
			}
		}
	}
}
原文地址:https://www.cnblogs.com/leon3286/p/1706257.html