Can the flash player play .wav files from a url?

前端 未结 5 1556
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 06:54

Let\'s say I have a wav file at a url:

http://hostname.com/mysound.wav

I\'m trying to load the wav file with the sound class like:

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 07:31

    here a simple class for loading and playing wav files from a url in flash using the open source popforge library: http://code.google.com/p/popforge/

    cheers!

        public class WavURLPlayer
         {
    
    
          public static function PlayWavFromURL(wavurl:String):void
          {
           var urlLoader:URLLoader = new URLLoader();
            urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
            urlLoader.addEventListener(Event.COMPLETE, onLoaderComplete);
            urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onLoaderIOError);
    
           var urlRequest:URLRequest = new URLRequest(wavurl);
    
           urlLoader.load(urlRequest);
          }
    
          private static function onLoaderComplete(e:Event):void
          {
           var urlLoader:URLLoader = e.target as URLLoader;
            urlLoader.removeEventListener(Event.COMPLETE, onLoaderComplete);
            urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, onLoaderIOError);
    
           var wavformat:WavFormat = WavFormat.decode(urlLoader.data);
    
           SoundFactory.fromArray(wavformat.samples, wavformat.channels, wavformat.bits, wavformat.rate, onSoundFactoryComplete);
          }
    
          private static function onLoaderIOError(e:IOErrorEvent):void
          {
           var urlLoader:URLLoader = e.target as URLLoader;
            urlLoader.removeEventListener(Event.COMPLETE, onLoaderComplete);
            urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, onLoaderIOError);
    
           trace("error loading sound");
    
          }
    
          private static function onSoundFactoryComplete(sound:Sound):void
          {
           sound.play();
          }
    
    
     }
    

提交回复
热议问题