Update (2/25/2008): This bug has been fixed as of Flash Player version 10.0.22.87. Download the new version from Adobe: http://get.adobe.com/flashplayer/
Problem:
Flash Player 10 distorts sounds sampled higher than 44KHz when using the loadSound function within ActionScript 2.0. This is a problem since many of the Flash mp3 players that exist today are written with AS 2.0 using this function: soundContainer.loadSound(urltoplay, true);
Solution:
There are three solutions to this problem. One is to re-sample all of your audio down to 44KHz, which very few people are willing to do. Adobe’s official fix is to set the stream property on the loadSound method to false, however, with this fix users must wait until the sound is completely loaded before they will hear anything.
That brings us to the third and in most cases, the best solution: re-write the audio player in AS 3.0. To start lets take a look at how AS 2.0 handles mp3 playback…
var my_sound:Sound;
var song = "demo.mp3";
function playMusic ()
{
my_sound = new Sound();
my_sound.loadSound(song, true);
}
function stopMusic ()
{
my_sound.stop();
}
Simple enough. The problem is that if a user has Flash Player 10 and tries to play a 48KHz sampling rate the sound is distorted and has popping and clicking sounds.
If you are interested in implementing Adobe’s official fix of setting the stream property to false you would have this:
function playMusic ()
{
my_sound = new Sound();
my_sound.onLoad = function(success:Boolean) {
if (success) {
my_sound.start();
}
};
my_sound.loadSound(song, false);
}
You can try this fix out to see if it will work for your needs. If you prefer to allow your users to continue to stream the audio files as they load, your code would look like this:
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
var song = "demo.mp3";
var snd:Sound = new Sound();
var channel:SoundChannel = new SoundChannel();
function playMusic(songSource:String){
var req:URLRequest = new URLRequest(song);
snd = new Sound();
snd.load(req);
channel = new SoundChannel();
channel = snd.play();
}
function stopMusic()
{
channel.stop();
}
If you are concerned about having to re-write a whole mp3 player UI just to fix the audio playback code you may want to consider using javascript to bridge AS 2.0 and AS 3.0. This would allow you to play 48KHz audio files without having to re-write a whole flash mp3 player.
Here is a link to Adobe’s official bug site:
Adobe
ActionScript 3.0 Sound API
LiveDocs
And a couple of people that have implemented this fix:
Mike Breidegam
Noel Webb
Feel free to contact me or leave a comment if you have any questions about this implementation of the Sound class in ActionScript.
A little more information about 44.1 vs 48 KHz audio:
“There is relatively little difference in audible quality between 44.1KHz and 48KHz, since the slight increase in frequency response is outside the range of human hearing.” And, “the improvement from 44.1 to 48 is marginal at best.” However, “It also happens to be fairly difficult to do a good conversion from 48KHz to 44.1KHz…”
Why 44.1KHz? Why not 48KHz?