AS3 audio-Wiedergabe und looping es

Ich versuche, eine Audiodatei zu spielen, im hintergrund mein Projekt aber so weit bisher erfolglos. Heres, was ich bisher bekommen haben.

package  {

    import flash.display.*; 
    import flash.events.*; 
    import flash.net.*; 
    import flash.media.*; 

    public class Music extends MovieClip {

        //Create a sound
        private var music:Sound;

        //Use a URLRequest for file path
        private var request:URLRequest;

        //Create a sound buffer
        private var buffer:SoundLoaderContext;

        //Create a sound channel
        private var channel:SoundChannel;

        public function Music() {
            //constructor code
            //Instantiate all sound objects
            buffer = new SoundLoaderContext(1000);
            request = new URLRequest("SMB3-Grassland-Map.mp3");
            music = new Sound(request, buffer);

            //Play music and assign it to a channel
            channel = music.play();

            //Add an event listener to the channel
            channel.addEventListener(Event.SOUND_COMPLETE, loopMusic);
        }

        //playMusic method restarts music
        private function playMusic()
        {
            channel = music.play();
            channel.addEventListener(Event.SOUND_COMPLETE, loopMusic);
        }

        //Channel event listener call playMusic method
        private function loopMusic(e:Event)
        {
            if (channel != null)
            {
                channel.removeEventListener(Event.SOUND_COMPLETE, loopMusic);

                playMusic();
            }
        }

    }
}

dies ist nur zur Wiedergabe einer externen audio-Datei und haben es kontinuierlich Schleife.

InformationsquelleAutor user1765914 | 2012-10-22
Schreibe einen Kommentar