Check if SoundChannel is playing sound

前端 未结 3 1699
陌清茗
陌清茗 2020-12-19 08:52

How to check reliably if a SoundChannel is still playing a sound?

For example,

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

var s: Song = new Song         


        
3条回答
  •  我在风中等你
    2020-12-19 09:27

    One of the ways to check if sound is still playing, and not using any managers, would be checking soundChannel.position in two consecutive enterFrame listener calls, if mismatched, 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;
    }
    

提交回复
热议问题