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.
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
Hi Paul
Thanks for your response. I have found that the code works fine on Windows Mobile but not on my Nokia Phone. It's a Nokia 6300. I can't find the device list for supported devices any more. I'm not sure where Adobe has tucked it away! I'm wondering if I thought that it has Flash Lite 2.1 when it only has 2.0. Does 2.0 support playing external mp3s? I thought that it did but maybe it doesn't. I think I'm going to have to try to get another Nokia phone?
Regards
Colleen.
ok - just did a web search for my phone... and it only has Flash Lite 2.0
See
http://www.flashlite4nokia.com/?page_id=54
Is this the problem? I thought that Flash Lite 2.0 was meant to support the playing of external MP3s. I also checked to see if the MP3 will play natively on the phone - and it does - it plays no problems.
Regards
Colleen.
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
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
North America
Europe, Middle East and Africa
Asia Pacific
Copyright © 2012 Adobe Systems Incorporated. All rights reserved.
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).