2013-02-21 156 views
0

我有這2個功能。正如你所看到的,第一個是流式傳輸視頻(女巫正在循環播放),第二個是流式傳輸音頻(女巫也在循環播放)。所以我需要當視頻播放音頻時開始運行並獨立循環,因爲我的音頻長度比視頻長度要長。任何想法我怎麼能設法做到這一點。請使用代碼。所有的音視頻流獨立as3

function NCListener(e:NetStatusEvent){ 

    if (e.info.code == "NetStream.Play.Stop") { 

     ns.play("http://media.easyads.bg/ads/display_ads_richmedia/video/avon/maria_ilieva/video_2.flv"); 
     shaker(null); 
     } 
    }; 


var sound:Sound = new Sound(); 
var soundChannel:SoundChannel= new SoundChannel(); 

sound.addEventListener(Event.COMPLETE, onSoundLoadComplete ); 

function onSoundLoadComplete(e:Event):void{ 
    sound.removeEventListener(Event.COMPLETE, onSoundLoadComplete); 
    soundChannel = sound.play(0, 9999); 
    soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete); 
} 

function onSoundChannelSoundComplete(e:Event):void{ 
    e.currentTarget.removeEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete); 
    soundChannel = sound.play(0, 9999); 
} 

回答

0

首先,你不需要 soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete);

它觸發時,聲音已經運行完畢,但因爲它是循環的,沒有必要再次播放。

首先,你需要招行

soundChannel = sound.play(0, 9999); 

,並把它的ns.play之後。所以,只要視頻開始,聲音就會開始播放。 然後,以防止它再次循環當視頻開始,剛剛檢查的SoundChannel存在:

if (soundChannel == null) 
    soundChannel = sound.play(0, 9999); 

請注意,是有沒有辦法,讓您的聲音同步與您的視頻後,它完全取決於FlashPlayer會。

+0

是的,我知道。但是如果我像你說的那樣,當視頻循環時它會再次播放第一個聲音(因爲它還沒有完成),並且它變得非常混亂! – Kircho 2013-02-21 12:24:18

+0

這就是爲什麼我需要同時播放,但要獨立循環播放。 – Kircho 2013-02-21 12:24:49

+0

我編輯了我的帖子=) – blue112 2013-02-21 12:28:31