前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >as 3加载mp3

as 3加载mp3

作者头像
meteoric
发布2018-11-15 16:10:14
9940
发布2018-11-15 16:10:14
举报
文章被收录于专栏:游戏杂谈游戏杂谈
代码语言:javascript
复制
package {
	import flash.display.*;
	import flash.events.*;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundLoaderContext;
	import flash.media.ID3Info;
	import flash.net.URLRequest;
	import flash.external.ExternalInterface;
	import flash.utils.*;
	
	public class alarmSound extends Sprite{
		private var alarm:Sound;
		private var mp3URL:String = "http://img.3bu.cn/ring/ring/201003041507952.mp3"; //"alarm_2.mp3";
		private var song:SoundChannel;
		
		function alarmSound() {
			inited();
		}
		
		private function inited():void {
			alarm = new Sound();
			
			var req:URLRequest = new URLRequest(mp3URL);
			var buffer:SoundLoaderContext = new SoundLoaderContext(5*1000);
			
			alarm.addEventListener(Event.COMPLETE, completeHandler);
			alarm.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
			alarm.addEventListener(ProgressEvent.PROGRESS, processHandler);
			alarm.addEventListener(Event.ID3, id3Handler);
			
			alarm.load(req, buffer);
			
			song = alarm.play(0, 0);//从0开始,循环1次
			
			song.addEventListener(Event.SOUND_COMPLETE, playCompleteHandler);			
			
		}
		
		private function processHandler(pro:ProgressEvent):void {
			var percent:Number = Math.floor(pro.bytesLoaded/pro.bytesTotal*100*100)/100;
			trace(pro.bytesLoaded + "---" + pro.bytesTotal + "已加载..." + percent + "%");
		}
		
		private function playCompleteHandler(...args):void {
			//trace(alarm.length/1000 + "---" + song.position/1000);
			
			var estimatedTotal:Number = Math.ceil(alarm.length / (alarm.bytesLoaded / alarm.bytesTotal));
			var position:Number = Math.round(100 * (song.position / estimatedTotal));
			
			trace(estimatedTotal/1000/60 + "----" + position);
		}
		
		private function completeHandler(evt:Event):void {
			alarm.removeEventListener(Event.COMPLETE, completeHandler);
			
			//trace(alarm.length + "---" + song.position);
		}
		
		private function ioErrorHandler(evt:Event):void {
			
		}
		
		private function id3Handler(evt:Event):void {
			var id3:ID3Info = alarm.id3;
			
			trace('音乐名称:' + id3.songName);
			trace('专辑: ' + id3.album);
			trace('艺术家:' + id3.artist);
		}
		
	}	
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2010-09-08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档