1

我有这个代码来流式传输 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;
}

如您所见,上面的代码还包括一些事件处理函数来处理我的播放/暂停按钮。一切正常,但音乐真正停止播放需要两秒钟的时间。重新启动也需要一段时间。有人知道为什么吗?我该如何解决?

谢谢

4

1 回答 1

0

Greensock tweener 具有淡入和淡出音频的功能,这将帮助您在收听音频文件时隐藏延迟。

导入 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});
}
于 2012-10-05T07:33:56.477 回答