AS3 sound 声音特定时间轴播放

AS3 sound sound specific timeline playing

我想播放声音的特定时间,我尝试使用位置,但帮不上忙,帮帮我 请帮助我,我需要从特定时间到特定时间播放文件,我尝试使用当前位置,但如何让它停止,我不想使用停止或关闭功能

        protected function application1_applicationCompleteHandler(event:FlexEvent):void
        {
            snd.load(ul);
            trace(snd.bytesTotal);
            trace(snd.bytesLoaded);
            trace(snd.isBuffering);
            snd.addEventListener(Event.COMPLETE,nad);
            snd.addEventListener(IOErrorEvent.IO_ERROR,rightu);

        }
        protected function rightu(event:IOErrorEvent):void
        {
            Alert.show("error");
        }
        public function nad(event:Event):void
        {

            trace(snd.bytesTotal);
            trace(snd.bytesLoaded); 
            trace(snd.isBuffering);

            p1.enabled=true;
        }



        protected function p1_clickHandler(event:MouseEvent):void
        {
            if(p1.label=="PLAY")
            {
                sc=snd.play(pause);
                sc.soundTransform=st;
                p1.label="PAUSE";

            }
            else
            {
                pause= sc.position; 
                sc.stop();
                p1.label="PLAY";

            }

        }


        protected function i1_clickHandler(event:MouseEvent):void
        {
            st.volume += .1;
            if(st.volume > 1)
            {
                st.volume = 1;
            } 
            sc.soundTransform=st;
        }


        protected function d1_clickHandler(event:MouseEvent):void
        {
            st.volume -= .1;
            if(st.volume <0)
            {
                st.volume=0;
            }
            sc.soundTransform=st;
        }


        protected function pa1_clickHandler(event:MouseEvent):void
        {

            sc.stop();
            p1.label="PLAY";
            pause=0;

        }


        protected function test_clickHandler(event:MouseEvent):void
        {
            trace(sc.position);
        }

    ]]>
</fx:Script>
<s:HGroup horizontalAlign="center" verticalAlign="middle">


<s:VGroup verticalAlign="middle" horizontalAlign="center">
    <mx:ProgressBar id="q"/>
    <s:Button id="p1" label="PLAY" enabled="false" click="p1_clickHandler(event)" />
    <s:Button id="pa1" label="STOP" click="pa1_clickHandler(event)"/>
    <s:Button id="i1" label="INCREASE" click="i1_clickHandler(event)"/>
    <s:Button id="d1" label="DECREASE" click="d1_clickHandler(event)"/>
    <s:Button id="test" click="test_clickHandler(event)"/>
</s:VGroup>
</s:HGroup>

如果你想播放 60 秒声音的第 21-40 秒(我认为你正在尝试这样做),那么当你播放声音时 sound.play(21) 然后尝试添加一个ENTER_FRAME 事件侦听器并检查通道的位置以在 40 处停止...

    private var stopPosition:int = 40000;
    private var pause:int = 21000; // set to 21 secs for example in code

    protected function p1_clickHandler(event:MouseEvent):void{
        if(p1.label=="PLAY"){
            sc=snd.play(pause);
            sc.soundTransform=st;
            p1.label="PAUSE";
            addEventListener(Event.ENTER_FRAME, checkPosition);
        } else {
            pause= sc.position; 
            stopTheSound();
        }
    }

    private function checkPosition(event:Event):void{
         if(sc.position >= stopPosition){
              stopTheSound();
         }
    }

    private function stopTheSound():void{
         sc.stop();
         p1.label="PLAY";
         removeEventListener(Event.ENTER_FRAME, checkPosition);
    }