首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ActionScript 3中Sound.length和SoundChannel.position的区别

ActionScript 3中Sound.length和SoundChannel.position的区别
EN

Stack Overflow用户
提问于 2010-01-21 04:53:23
回答 1查看 2.4K关注 0票数 0

谁能告诉我为什么或者我必须做什么来解决下面的问题?

我加载了一首歌曲,当我获得长度时,歌曲永远不会达到这个值。

这是另一个人AS3 – SoundChannel.position never reaches Sound.length的问题文档

下面是我的代码

代码语言:javascript
复制
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);
}
EN

回答 1

Stack Overflow用户

发布于 2010-01-21 05:02:51

这是Flash中的一个已知问题,如果你在周围搜索,你会找到几个关于这个问题的论坛帖子。据我所知,你要么自己滚,要么找一个为你做这件事的库。

有几个项目确实可以(正确地)处理音频。在Here's上查看它们的列表。

您可能要查看的第一个是popforge开源音频库。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2104882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档