我有这段代码来传输一个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;
}
正如您所看到的,上面的代码还包括一些事件处理函数来处理我的播放/暂停按钮。一切正常,但音乐实际上停止播放需要两秒钟。它还需要一段时间才能重新开始。有人知道为什么吗?我该如何解决它?
由于
答案 0 :(得分:0)
Greensock tweener具有淡入和淡出音频的功能,可以帮助您在听到音频文件时隐藏延迟。
导入Greensock tweener并激活插件
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});
}