检查 SoundChannel 是否正在播放声音

编程入门 行业动态 更新时间:2024-10-11 01:10:28
本文介绍了检查 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 是否正在播放声音

本文发布于:2023-11-05 18:15:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561520.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正在播放   声音   SoundChannel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!