有人可以告诉我为什么或要做些什么来解决以下问题?
我加载一首歌,当我得到长度时,歌曲永远不会达到这个值。
这是另一个人AS3 – SoundChannel.position never reaches Sound.length
的问题文档这是我的代码
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.events.Event;
import flash.events.IOErrorEvent;
var snd:Sound = new Sound();
var channel:SoundChannel;
var statusTextField:TextField = new TextField();
statusTextField.autoSize=TextFieldAutoSize.LEFT;
var req:URLRequest=new URLRequest("http://localhost/chance_teaser.mp3");
try {
snd.load(req);
channel=snd.play();
} catch (err:Error) {
trace(err.message);
}
snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
this.addChild(statusTextField);
function enterFrameHandler(event:Event):void {
var loadTime:Number=snd.bytesLoaded/snd.bytesTotal;
var loadPercent:uint=Math.round(100*loadTime);
var estimatedLength:int = Math.ceil(snd.length / (loadTime));
var playbackPercent:uint = Math.round(100 * (channel.position / estimatedLength));
statusTextField.text = "Sound file's size is " + snd.bytesTotal + " bytes.\n"
+ "Bytes being loaded: " + snd.bytesLoaded + "\n"
+ "Percentage of sound file that is loaded " + loadPercent + "%.\n"
+ "Sound playback is " + playbackPercent + "% complete. \n"
+ "Lengh of sound is " + snd.length + "\n"
+ "Pos of sound is " + channel.position + "\n";
}
function errorHandler(errorEvent:IOErrorEvent):void {
statusTextField.text="The sound could not be loaded: "+errorEvent.text;
}
function soundCompleteHandler(event:Event):void {
statusTextField.text = statusTextField.text + "\n The sound has finished playing.";
removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
答案 0 :(得分:0)
这是Flash中的一个已知问题,如果您在谷歌周围找到几个论坛帖子就可以了。据我所知,你要么自己动手,要么找一个能为你做这件事的图书馆。
有几个项目可以处理音频(正确)。 Here's列出了它们。
您可能要研究的第一个是popforge开源音频库。