actionscript-3 - 为什么在Flash中暂停MP3流时会有延迟

标签 actionscript-3 flash audio soundchannel

我有此代码以流mp3文件:

var isPlaying:Boolean;
var pausePoint:Number;

var soundChannel:SoundChannel = new SoundChannel();
var sound:Sound = new Sound( new URLRequest( 'mp3file.mp3' ) );
var volumeAdjust:SoundTransform = new SoundTransform();

soundChannel = sound.play();
isPlaying = true;

function clickPlayPause(evt:MouseEvent) {

    if (isPlaying) 
    {
       pausePoint = soundChannel.position;
       soundChannel.stop();
       //hide pause sign
       control_mc.play_btn.pausee.alpha = 0;
       //show play sign
       control_mc.play_btn.playy.alpha = 1;
       isPlaying = false;

    } else {

        soundChannel = sound.play(pausePoint);
        isPlaying = true;
       //hide play sign
       control_mc.play_btn.playy.alpha = 0;
       //show pause sign
       control_mc.play_btn.pausee.alpha = 1;

    }
}

function clickStop(evt:MouseEvent) {
    if (isPlaying) {
        soundChannel.stop();
        isPlaying = false;
    }
    pausePoint = 0.00;
}

如您所见,上面的代码还包括一些事件处理功能,用于处理我的播放/暂停按钮。一切正常,但是音乐实际上要花两秒钟才能真正停止播放。重新启动备份也需要一段时间。有人知道为什么是这样吗?以及我该如何解决?

谢谢

最佳答案

Greensock补间动画具有淡入和淡出音频的功能,可帮助您在听到音频文件时隐藏延迟。

导入Greensock补间动画并激活插件

import com.greensock.*;
import com.greensock.plugins.*;


TweenPlugin.activate([VolumePlugin]);

然后
if(palying){
   TweenLite.to(soundChannel, .5, {volume:0});
}else{
   TweenLite.to(soundChannel, .5, {volume:1});
}

关于actionscript-3 - 为什么在Flash中暂停MP3流时会有延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12741257/

相关文章:

actionscript-3 - Flash AS3 声音在通过removeChild删除影片剪辑后播放

javascript - 当AS的ExternalInterface准备好时告诉JS

c++ - 在 Ubuntu 中使用 C/C++ 进行线路输入插孔感知

java - 如何以正确的时机将音频数据发送到 Icecast?

flash - 动态音频生成 Actionscript 3

flash - 录制音频有效,播放方式太快

javascript - Javascript 和 Flash/ActionScript 之间的交互无需外部接口(interface)?

python - 将麦克风数据转换为频谱

performance - Adobe AIR 与 iOS 8 相关的问题和性能不佳

vb.net - 在 SwfDotNet 库 (VB.NET) 中将透明 PNG 添加到 SWF