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

前端 未结 5 1545
隐瞒了意图╮
隐瞒了意图╮ 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:14

    Flash itself does not support playing .wav files. Flash/Flex Builder compiles it directly into a Sound object ready to be played in your scripts, but for external .wav sound, the Flash SDK won't help you.

    You will need to read the .wav data yourself and make Flash play, or: there are a couple of third-party libraries around that do this for you. The above post uses popforge, here's tutorial that demonstrates as3wavsound playing an external .wav file from a URL:

    http://active.tutsplus.com/tutorials/media/quick-tip-play-external-wav-files-in-as3/

    0 讨论(0)
  • 2020-12-09 07:24

    Yes, you can. I have made Wav/Au Flash player, that can play stream wav, encoded in G.711 or PCM in any bitlength and samplerate. Licensed under GPLv2, here: http://blog.datacompboy.ru/2009/10/15/wav-au-flash-player/

    0 讨论(0)
  • 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();
          }
    
    
     }
    
    0 讨论(0)
  • 2020-12-09 07:32

    Directly you cannot but there are workarounds thanks to the ByteArray ; )

    Check this out :

    http://richapps.de/?p=97

    EDIT:

    The previous link being a bit old I reckon you should also have a look on Andre and Joa's fabulous PopForge library. There's actually a wav decoder class there as well.

    http://code.google.com/p/popforge/source/browse/#svn/trunk/flash/PopforgeLibrary/src/de/popforge/format/wav

    0 讨论(0)
  • 2020-12-09 07:35

    The ActionScript documentation for the Sound class states that only MP3 files are supported.

    0 讨论(0)
提交回复
热议问题