如何可靠地检查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?发布于 2008-10-11 21:11:27
我做了一些研究,但我找不到一种方法来查询任何对象来确定是否正在播放声音。看起来,您必须编写一个包装器类并自己管理它。
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;
}
}
}发布于 2012-10-05 19:05:09
我知道这真的很古老,但我发现这个链接很有帮助。它解释了如何从某个点监控和播放文件。
http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d21.html
发布于 2012-10-07 01:22:09
检查声音是否仍在播放而不使用任何管理器的方法之一是在两个连续的enterFrame侦听器调用中检查soundChannel.position,如果不匹配,则声音仍在播放。
private var oldPosition:Number;
function onEnterFrame(e:Event):void {
var stillPlaying:Boolean;
var newPosition=soundChannel.position;
if (newPosition-oldPosition>1) stillPlaying=true; else stillPlaying=false;
oldPosition=newPosition;
}https://stackoverflow.com/questions/194150
复制相似问题