• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Why isn't this embedded sound file playing?

Explorer ,
Aug 12, 2013 Aug 12, 2013

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.

TOPICS
ActionScript

Views

961

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 12, 2013 Aug 12, 2013

Copy link to clipboard

Copied

your path is probably wrong.

start with a simple path and work your way to the path you want.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 12, 2013 Aug 12, 2013

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 12, 2013 Aug 12, 2013

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 12, 2013 Aug 12, 2013

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 12, 2013 Aug 12, 2013

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 19, 2013 Aug 19, 2013

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 19, 2013 Aug 19, 2013

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines