Skip navigation
Currently Being Moderated

playing an MP3 file in Flash Lite 2.1

Apr 20, 2009 2:22 AM

Hi

 

I am trying to play an MP3 File in Flash Lite 2.1. The filename of the MP3 file is imported from an XML file.

 

Here is a copy and paste from the help file on how to do this:

 

// create a new Sound object
var my_sound:Sound = new Sound();
// If the sound loads, play it; if not, trace failure loading.
my_sound.onLoad = function(success:Boolean) {
if (success) {
my_sound.start();
status_txt.text = "Sound loaded";
} else {
status_txt.text = "Sound failed";
}
};
// Load the sound.
my_sound.loadSound("song1.mp3", true);

 

When I test this code on its own, it does work fine for me. However, I want the above to be executed inside a function that does a number of other things... and this is where I run into problems.

 

Here is a sample of what I'm trying to get working.

 

function myMusic() {

// create a new Sound object
var my_sound:Sound = new Sound();
// If the sound loads, play it; if not, trace failure loading.
my_sound.onLoad = function(success:Boolean) {
    if (success) {
    my_sound.start();
    status_txt.text = "Sound loaded";
    } else {
    status_txt.text = "Sound failed";
    }
}
// Load the sound.
my_sound.loadSound("MOO.MP3", true);
}

 

myMusic();

 

 

I think it's got to do with the fact that once I put it inside a function you are nesting functions (there is a function call from the onLoad event). Can anyone tell me how to make this work?

 

I tried changed the line:

my_sound.onLoad=function(success: Boolean) {

to

my_sound.onLoad=myFunctionName(parameters go here)

and then I created a funciton called myFunctionName but I wasn't sure how to send the sound object or what parameters the function should have or how to get the .start() method to work inside the new function.

 

Any ideas, would be greatly appreciated. I've been tearing my hair out on this one for two days! I don't look good bald!

 

Regards

 

Ellie.

 

  • Currently Being Moderated
    Community Member
    Apr 21, 2009 1:52 AM

    Hi Ellie,

     

    The code you supplied works fine for me, so there must be something else in the function that is conflicting with the Sound object.

     

    function myMusic() {

    // create a new Sound object
    var my_sound:Sound = new Sound();
    // If the sound loads, play it; if not, trace failure loading.
    my_sound.onLoad = function(success:Boolean) {
        if (success) {
        my_sound.start();
        status_txt.text = "Sound loaded";
        } else {
        status_txt.text = "Sound failed";
        }
    }
    // Load the sound.
    my_sound.loadSound("MOO.MP3", true);
    }

     

    myMusic();

     

     

    Are you getting a response from the onLoad event, even if it fails?

    Is the name of the mp3 file correct?

    Are you loading the Sound from the library or from an external file?

    What else are you doing in the function that could be conflicting?

     

    Regards

    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Apr 24, 2009 1:56 AM

    Hi Colleen,

     

    It seems the 6300 supports playing mp3 if it's embedded in the flash file using attchSound(), but is not supported when loading externally using loadSound().

     

    Flash Lite 2 does support mp3, but it also depends on the implementation of the device as well. The 6300 looks to be an exception to the rule if loading sound externally. Its a shame, because its a good phone!

     

    Regards

    Paul

    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2009 7:03 AM

    I have problem playing Mp3 files from 3rd party servers

    if song is in the same server where the player is  the equalizer and ID3 tag works fine

     

    but if not on the same server the song plays but without equalizer or song info

     

    to see the error  try playing this song

     

    Rihanna Mp3

    http://www.roomp3.com/mp3-3178-Rihanna-Disturbia.html

    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points