Check if SoundChannel sounds

How to check reliability if SoundChannel still plays sound?

For instance,

[Embed(source="song.mp3")] var Song: Class; var s: Song = new Song(); var ch: SoundChannel = s.play(); // how to check if ch is playing? 
+4
source share
3 answers

I did a little research, and I cannot find a way to query any object to determine if the sound is playing. You will 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; } } } 
+10
source

I know this is really old, but I found this link which, in my opinion, is very useful. he explains how to control and play a file from a specific point.

http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d21.html

+1
source

One way to check if the sound continues to sound, rather than using any managers, is to check soundChannel.position in two consecutive calls to the enterFrame listener, if they do not match, then the sound is still playing.

 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; } 
0
source

Source: https://habr.com/ru/post/1277673/


All Articles