zoukankan      html  css  js  c++  java
  • as 3加载mp3

    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);
    		}
    		
    	}	
    }
  • 相关阅读:
    无锁队列的实现 | 酷壳 CoolShell.cn
    简明 Vim 练级攻略 | 酷壳 CoolShell.cn
    分享:lucene 的评分机制
    JS实现面向对象的设计
    EF架构~性能高效的批量操作(Update篇)
    将不确定变为确定~transactionscope何时提升为分布式事务?
    将不确定变为确定~Linq to SQL不能随机排序吗?
    vs2012~ 开发人员的福音
    白领职场必懂的22条潜规则(转载)
    经典面试题(转载)
  • 原文地址:https://www.cnblogs.com/meteoric_cry/p/1821370.html
Copyright © 2011-2022 走看看