Copy link to clipboard
Copied
I've been going through a few tutorials, trying to find how to embed audio files and play them in AS3, and they tend to show examples which are very similar. However when I try to use these examples, nothing is played. My mp3 file will be embedded successfully, all the lines of code will execute sucessfully, but there will just be no sound. Take the following code, for instance:
[code]
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Sound;
public class Main extends Sprite
{
[Embed(source='/../lib/Kalimba.mp3')]
private var MySound : Class;
private var sound : Sound;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null😞void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
sound = (new MySound()) as Sound;
sound.play();
}
}
}
[/code]
What's going wrong here? Many examples online basically use this code, just changing variable names and the like. Thanks.
Copy link to clipboard
Copied
your path is probably wrong.
start with a simple path and work your way to the path you want.
Copy link to clipboard
Copied
It's the right path, and I tried using a simple path to be sure. Flash Builder in particular won't even let me build the thing without the correct path.
Copy link to clipboard
Copied
then check on a flash builder forum to see what error there could be because it's not in your code. that code will work in flash that uses a flex sdk.
Copy link to clipboard
Copied
Apparently it's somehow linked to that file. I tried Kalimba.mp3, Maid with the Flaxen Hair.mp3, and Sleep Away.mp3, all of which are Windows 7 defaults in Libraries\Music\Sample Music. None of them worked. Then I downloaded a random mp3 file elsewhere and tried to use it, and it worked just fine (Blackbird Blackbird - Heartbeat.mp3 from http://www.last.fm/music/+free-music-downloads/sample). Earlier I tried using converters to make sure Kalimba was at 44100 Hz, but that didn't seem to work. What's the difference?
Copy link to clipboard
Copied
i don't know the difference between your mp3's that play and those that do not, but both bitrate and sampling frequency are important factors for flash.
Copy link to clipboard
Copied
Alright, I'll probably play around with it some later and see what the differences are. Thanks.
I think I converted the bitrates in one of the "bad" files to be the same as in the "good" file, but it didn't work; probably either the frequency or an error in the conversion had something to do with it. One thing I've noticed though is that when I download mp3 files off of different sites on the Internet (I've tried a some more out since), they all seem to work fine, but these few that came with Windows in the C:\Users\Public\Music\Sample Music folder don't - it's been a very real line in the dust so far.
Copy link to clipboard
Copied
whenever i've had sound file problems i open in audition and save with the same settings as the original file. almost always that solves the problem.