获取声音的总时间和当前时间? [英] Get sound's total time and current time?

查看:129
本文介绍了获取声音的总时间和当前时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个球员在闪光的ActionScript 3。我需要的声音文件的声音文件和当前时间的总时间。 我的code:

I have a player in flash ActionScript 3. I need to take a the total time of the sound file and current time of the sound file. My code:

function onPlayProgress(evt:Event):void {
            var sndLength:int = Math.ceil(snd.length /(snd.bytesLoaded / snd.bytesTotal));
            var seekbar = 100 * (channel.position / sndLength);
            playBar.seekbar.x = seekbar*5.8;
            var _totalTime:Number = (((snd.length /(snd.bytesLoaded / snd.bytesTotal))*0.001/60));

什么是当前的时间?

What is current time?

推荐答案

我不是你所提供的code样品试图传达完全清楚,但如果你想获得声音的当前位置正在播放,你会做这样的事情:

I'm not entirely clear on what the code sample you provided is trying to communicate, but if you want to get the current position of a sound that's playing you would do something like this:

protected var sound:Sound; 
protected var soundChannel:SoundChannel;

protected function loadSound():void
{
    sound = new Sound(new URLRequest("path_to_sound.mp3"));
    sound.addEventListener(Event.COMPLETE, onSoundLoadComplete);
{

protected function onSoundLoadComplete(e:Event):void
{
    sound.removeEventListener(Event.COMPLETE, onSoundLoadComplete);
    soundChannel = sound.play();
    addEventListener(Event.ENTER_FRAME, onEnterFrame);
}

//Calculuate the sound time
protected function onEnterFrame(e:Event):void
{
    var minutes:uint = Math.floor(soundChannel.position / 1000 / 60);
    var seconds:uint = Math.floor(soundChannel.position / 1000) % 60;
    trace('position: ' + minutes + ':' + seconds);        
};

这篇关于获取声音的总时间和当前时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆