Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flash

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:

var url:String = "http://hostname.com/test.wav";
var urlRequest:URLRequest = new URLRequest(url);
var sound:Sound = new Sound();
sound.load(urlRequest);
sound.play();

However, this doesn't seem to work. Can flash player play wav files, or is it just mp3s?

like image 664
marketer Avatar asked Mar 20 '09 22:03

marketer


People also ask

What will play WAV files?

Since WAV is quite a popular format, almost all devices today support it using built-in media players. On Windows, the Windows Media Player is capable of playing WAV files. On MacOS, iTunes or QuickTime can play WAV files. On Linux, your basic ALSA system can play these files.

Where can I play a WAV file?

WAV files can be opened with Windows Media Player, VLC, iTunes, Groove Music, Winamp, Clementine, XMMS, and very likely some other popular media player applications as well.

Can Chrome play WAV files?

Yes, Chrome OS can play . wav files. However, since . wav files can be encoded with a variety of codecs, Google Chrome OS cannot read all of them.

Can all devices play WAV files?

Actually, Android has suppored WAV audio playback since Android 4.1, but it is a common phenomenon if the WAV files are not encoded in standard formats or fail to decode due to hardware or system glitch. Apart from can't play . wav files, Android devices can't play QuickTime MOV files, etc.


2 Answers

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

like image 57
Chad Birch Avatar answered Sep 21 '22 10:09

Chad Birch


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();
      }


 }
like image 31
fluxa Avatar answered Sep 23 '22 10:09

fluxa