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?
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.
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.
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.
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.
The ActionScript documentation for the Sound class states that only MP3 files are supported.
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With