本文介绍了检查 SoundChannel 是否正在播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何可靠地检查 SoundChannel 是否仍在播放声音?
How to check reliably if a SoundChannel is still playing a sound?
例如
[Embed(source="song.mp3")] var Song: Class; var s: Song = new Song(); var ch: SoundChannel = s.play(); // how to check if ch is playing? 推荐答案我做了一些研究,但找不到查询任何对象以确定是否正在播放声音的方法.看来您必须编写一个包装类并自行管理它.
I've done a little research and I can't find a way to query any object to determine if a sound is playing. You'll have to write a wrapper class and manage it yourself it seems.
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; } } }更多推荐
检查 SoundChannel 是否正在播放声音
发布评论