flash - 检查SoundChannel是否正在播放声音

标签 flash actionscript-3 audio soundchannel

如何可靠地检查SoundChannel是否仍在播放声音?

例如,

[Embed(source="song.mp3")]
var Song: Class;

var s: Song = new Song();
var ch: SoundChannel = s.play();

// how to check if ch is playing?

最佳答案

我进行了一些研究,但找不到找到任何对象来确定声音是否正在播放的方法。您似乎必须编写一个包装器类并对其进行管理。


package
{
    import flash.events.Event;
    import flash.media.Sound;
    import flash.media.SoundChannel;

    public class SoundPlayer
    {
        [Embed(source="song.mp3")]
        private var Song:Class;

        private var s:Song;
        private var ch:SoundChannel;
        private var isSoundPlaying:Boolean;

        public function SoundPlayer()
        {
            s = new Song();
            play();
        }

        public function play():void
        {
            if(!isPlaying)
            {
                ch = s.play();
                ch.addEventListener(
                    Event.SOUND_COMPLETE,
                    handleSoundComplete);
                isSoundPlaying = true;
            }
        }

        public function stop():void
        {
            if(isPlaying)
            {
                ch.stop();
                isSoundPlaying = false;
            }
        }

        private function handleSoundComplete(ev:Event):void
        {
            isSoundPlaying = false;
        }
    }
}

关于flash - 检查SoundChannel是否正在播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/194150/

相关文章:

apache-flex - ActionScript 中组件不同部分的不同工具提示

ios - 在 iOS 10 中使用新键盘点击声音的官方方式

android - Flash Air 与 iOS 和 Android 的兼容性

ios - Flash 在 OS X/iOS 上不工作?

actionscript-3 - AS3 对象箱和重置按钮

javascript - 外部接口(interface)回调未定义 AS3

flash - 高效的不规则位图打区

android - Android实时静音检测

android - Android声音重叠命令行ffmpeg不起作用

apache-flex - 将绘制的flash/flex UIComponent导出到基于矢量的打印文件的方法