flash - 如何在 AS3 flash 中暂停/播放嵌入声音

标签 flash actionscript-3 audio

我有一个长度为 1 分 30 秒的声音。我将它嵌入到我的 swf 中并将其设置为与框架同步。我需要的是能够通过 ActionScript 暂停和播放这个声音。

有人知道怎么做吗?

最佳答案

//number that is redefined when the pause button is hit
var pausePoint:Number = 0.00;

//a true or false value that is used to check whether the sound is currently playing
var isPlaying:Boolean;

//think of the soundchannel as a speaker system and the sound as an mp3 player
var soundChannel:SoundChannel = new SoundChannel();
var sound:Sound = new Sound(new URLRequest("SOUND.mp3"));

//you should set the xstop and xplay values to match the instance names of your stop button and play/pause buttons
xstop.addEventListener(MouseEvent.CLICK, clickStop);
xplay.addEventListener(MouseEvent.CLICK, clickPlayPause);

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

function clickPlayPause(evt:MouseEvent) {
    if (isPlaying) {
        pausePoint = soundChannel.position;
        soundChannel.stop();
        isPlaying = false;
    } else {
        soundChannel = sound.play(pausePoint);
        isPlaying = true;
    }
}

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

关于flash - 如何在 AS3 flash 中暂停/播放嵌入声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1211393/

相关文章:

flash - Flash AS3:ReferenceError:错误#1056:无法创建属性

angularjs - ngaudio屏幕的单击会停止音频

asp.net - 如何转换上传的视频并从此文件中获取屏幕截图?

php - 防止成人图片被上传到照片网站的想法

flash - Flex声音提取并保存mp3

actionscript-3 - 将 < 或 > 运算符作为参数传递给函数?

actionscript-3 - AS3,将 SWF 作为自定义类型加载

ios - 应用音频未播放

iphone - 我可以从 MPMusicPlayerController 获取 Audio Session /应用音频单元进行播放吗?

flash - h264 mp4 索引到前端命令行