maxl0rd / standingwave3

Flash ActionScript3 dynamic audio library
http://www.noteflight.com
162 stars 28 forks source link

Problems with Performances and SoundSource #24

Open seultwo opened 12 years ago

seultwo commented 12 years ago

Hello, I have a problems with Performances and SoundSource. I tried your exemple for SoundSource but it doesn't work . It works good with sineSource and embed file but not with urlrequest. Can you help me? Ask me if you want precisions.

My code:

package {

import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.net.URLRequest;
import com.noteflight.standingwave3.performance.AudioPerformer;
import com.noteflight.standingwave3.elements.IAudioSource;
import com.noteflight.standingwave3.performance.IPerformance;
import com.noteflight.standingwave3.elements.AudioDescriptor;
import com.noteflight.standingwave3.output.AudioPlayer;
import com.noteflight.standingwave3.sources.SineSource;
import com.noteflight.standingwave3.sources.SoundSource;
import com.noteflight.standingwave3.performance.ListPerformance;
/**
 * ...
 * @author Vincent
 */
public class Main extends Sprite 
{

    public function Main():void 
    {

        var player:AudioPlayer = new AudioPlayer(4096);
        var url_base:String = "sounds/base_1.mp3";
        var url_ambiance:String = "sounds/ambiance_1.mp3";
        var url_instru:String = "sounds/instru_1.mp3";
        var audio_desc:AudioDescriptor = new AudioDescriptor(44100,2);
        //var source:IAudioSource = new SineSource(new AudioDescriptor(), 5, 440);
        var source_base_0:IAudioSource;
        var source_ambiance_0:IAudioSource;
        var source_instru_0:IAudioSource;
        var sequence:ListPerformance = new ListPerformance();

        function handleSoundComplete(e:Event):void
        {
            trace(e.target.bytesLoaded);
            trace("ok2");
            source_base_0 = new SoundSource(e.target as Sound);
            sequence.addSourceAt(1, source_base_0, 0, 0);
        }
            var sound2:Sound = new Sound(new URLRequest("sounds/ambiance_1.mp3"));
            sound2.addEventListener(Event.COMPLETE, handleSoundComplete_2);

        function handleSoundComplete_2(e2:Event):void
        {
            trace(e2.target.bytesLoaded);
            trace("ok2 - ambiance");

            source_ambiance_0 = new SoundSource(e2.target as Sound);
            sequence.addSourceAt(1, source_ambiance_0, 0, 0)
        }

        var AP_seq:IAudioSource =  new AudioPerformer(sequence, audio_desc);
        //AP_seq.mixGain = -12;
        player.play(AP_seq);
    }
}

}