Displaying Duration and Position

[SIZE=1]Im trying to make a flash music player, and im having trouble displaying the length of the track and the time played.[/SIZE]

[SIZE=1]Here is the actionscript used, all it does is give me undefined/undefined. Im using flash mx 2004 pro. Any help would be appreciated.[/SIZE]

[FONT=Helvetica]

 
[FONT=Helvetica]this.onEnterFrame = function ()[/FONT]
[FONT=Helvetica]{[/FONT]
[FONT=Helvetica]          dur = int([COLOR=#ff1500]My_Sound[/COLOR].duration / 1000);[/FONT]
[FONT=Helvetica]          pos = int([COLOR=#ff1500]My_Sound[/COLOR].position / 1000);[/FONT]
 
[FONT=Helvetica] playTime = {};[/FONT]
[FONT=Helvetica] playTime.minutes = int(pos / 60);[/FONT]
[FONT=Helvetica] playTime.seconds = int(pos % 60);[/FONT]
[FONT=Helvetica] playTime.total = checkDigits(playTime.minutes) + ":" + checkDigits(playTime.seconds);[/FONT]
 
[FONT=Helvetica] trackTime = {};[/FONT]
[FONT=Helvetica] trackTime.minutes = int(dur / 60);[/FONT]
[FONT=Helvetica] trackTime.seconds = int(dur % 60);[/FONT]
[FONT=Helvetica] trackTime.total = checkDigits(trackTime.minutes) + ":" + checkDigits(trackTime.seconds);[/FONT]
 
[FONT=Helvetica] if (timetext.text == undefined){[/FONT]
[FONT=Helvetica]     timetext.text = playTime.total + " / " + trackTime.total[/FONT]
[FONT=Helvetica] }[/FONT]
[FONT=Helvetica] else[/FONT]
[FONT=Helvetica] {[/FONT]
[FONT=Helvetica]     timetext.text = playTime.total + " / " + trackTime.total;[/FONT]
[FONT=Helvetica] }[/FONT]
[FONT=Helvetica]};[/FONT]

[/FONT]

Anyone?

I don’t know…I can help you make a simplier one…you want an audio player, right? In flash?

…you may want to set up your sound object first


var My_Sound:Sound = new Sound();
My_Sound.loadSound("soundToLoad");
My_Sound.start(0);

var my_sound:Sound = new Sound();
my_sound.loadSound("my_sound.mp3");
my_sound.start(0)
   	dur = int(My_Sound.duration / 1000);
   	pos = int(My_Sound.position / 1000);

   playTime = {};
   playTime.minutes = int(pos / 60);
   playTime.seconds = int(pos % 60);
   playTime.total = checkDigits(playTime.minutes) + ":" + checkDigits(playTime.seconds);

   trackTime = {};
   trackTime.minutes = int(dur / 60);
   trackTime.seconds = int(dur % 60);
   trackTime.total = checkDigits(trackTime.minutes) + ":" + checkDigits(trackTime.seconds);

       timetext.text = playTime.total + " / " + trackTime.total
   }

still doesnt work, no output messages or anything, just says undefined and nothing plays. file is in directory and everything.

my_sound.loadSound("./my_sound.mp3");

?

still nothing…i would upload the flash but cant attach that large…

he song’s in rthe swf? in that case, you need to load the linkage id.

right-click sound – > linkage --> export for AS --> type in an id

then
my_sound.loadSound(“linkageID”);

maybe like this but can`t see your checkDigits function

var my_sound:Sound = new Sound();
my_sound.loadSound("my_sound.mp3", false);
onEnterFrame = function () {
	if (my_sound.getBytesLoaded() == my_sound.getBytesTotal()) {
		this.onEnterFrame = checks;
		my_sound.start();
	}
};
playTime = {};
trackTime = {};
function checks() {
	var dur = int(my_sound.duration/1000);
	var pos = int(my_sound.position/1000);
	playTime.minutes = int(pos/60);
	playTime.seconds = int(pos%60);
	playTime.total = checkDigits(playTime.minutes)+":"+checkDigits(playTime.seconds);
	trackTime.minutes = int(dur/60);
	trackTime.seconds = int(dur%60);
	trackTime.total = checkDigits(trackTime.minutes)+":"+checkDigits(trackTime.seconds);
	timetext.text = playTime.total+" / "+trackTime.total;
}

nathan:
The song is external, its a .mp3 in the folder where all my .swfs are.

stringy:


function checkDigits(toCheck)
{
   var _l1 = toCheck;
   _l1 = "0" + _l1;
   _l1 < 10 ? ("0" + _l1) : (_l1);
   return(_l1 < 10 ? ("0" + _l1) : (_l1));
}

heres a file using the code i posted earlier -just added a simple preloader
http://www.fmx6.com/teststuff/sound.swf
Hope it is what you wanted
entire code

var my_sound:Sound = new Sound();
my_sound.loadSound("my_sound.mp3", false);
onEnterFrame = function () {
	if (my_sound.getBytesLoaded()>10) {
		timetext.text = Math.floor(100*my_sound.getBytesLoaded()/my_sound.getBytesTotal())+" %loaded";
	}
	if (my_sound.getBytesLoaded() == my_sound.getBytesTotal()) {
		this.onEnterFrame = checks;
		my_sound.start();
	}
};
playTime = {};
trackTime = {};
function checkDigits(toCheck) {
	var _l1 = toCheck;
	_l1 = "0"+_l1;
	_l1<10 ? ("0"+_l1) : (_l1);
	return (_l1<10 ? ("0"+_l1) : (_l1));
}
function checks() {
	var dur = int(my_sound.duration/1000);
	var pos = int(my_sound.position/1000);
	playTime.minutes = int(pos/60);
	playTime.seconds = int(pos%60);
	playTime.total = checkDigits(playTime.minutes)+":"+checkDigits(playTime.seconds);
	trackTime.minutes = int(dur/60);
	trackTime.seconds = int(dur%60);
	trackTime.total = checkDigits(trackTime.minutes)+":"+checkDigits(trackTime.seconds);
	timetext.text = playTime.total+" / "+trackTime.total;
}

just make sure my_sound is in the same directory and that the extension".mp3" is not capitalized