3 Replies - 10781 Views - Last Post: 03 March 2007 - 04:37 PM

#1 dabearunleashed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-February 07

MP3 Music Player

Posted 02 March 2007 - 05:42 AM

hey y'all.
i bin workin on a streaming Mp3 Music Player for my website. its the first time i attemped real actionscripting for my music player, before i just had movieclips with imported sound. this time im trying to load MP3s from external source. i been lookin in books and sites to help with the code. i got it workin and it looks quite good, but i have a problem. when it loads you HAVE to press play button to start the music, i would prefer it to play as soon as it has loaded. and when the song has finished, it stops instead of automatically playing the next song. you HAVE to press skip button to play the next song.

so if anybody could help me to get this to:
play from start/loaded
play next track once song has finished.

it would be very much appreciated.

this is my code below.

 

this.onEnterFrame = function () {
sload = mySound.getBytesLoaded();
stotal = mySound.getBytesTotal();
percentload = (Math.round((sload/stotal) * 100)) + "%";
if (counter < 2) {
counter = counter + 1;

// txt file telling where the mp3s are and there names.
loadVariablesNum("tracks.txt", 0);

// character to split track
songtitle = musictitle.split(":");
count2 = 0;
songplaying = (count2+1) + " - " + songtitle[count2];
}
if (stopped!=true) {
mySoundDuration=Math.round(_root.mySound.duration/1000);
mySoundPosition=Math.round(_root.mySound.position/1000);
texttime = mySoundPosition;
timemin = 0;
if (texttime < 10) {
	texttime = "0" + texttime;
}
while(texttime >= 60) {
	texttime = texttime - 60;
	timemin = timemin + 1;
if (texttime < 10) {
	texttime = "0" + texttime;
}
}
}
timeformat = timemin + ":" + texttime;

//Rewind
if (REV==1 && mySoundPosition>0) {
	_root.mySound.stop();
	mySoundPosition=mySoundPosition-1;
	_root.mySound.start(mySoundPosition,0);
	}
revButton.onPress = function () {
	REV=1;
	mySoundPosition=Math.round(_root.mySound.position/1000);
	//
}
revButton.onRelease = function () {
	REV=0
}

//Fast Forward
if (FF==1 && mySound.position<mySound.duration) {
		_root.mySound.stop();
		mySoundPosition=mySoundPosition+1;
		_root.mySound.start(mySoundPosition,0);
	}
FFButton.onPress = function () {
	FF=1;
	mySoundPosition=Math.round(_root.mySound.position/1000);
}
FFButton.onRelease = function () {
	FF=0
}


}




and heres a shot of my player
Attached Image



thanks in advance


Bear

Is This A Good Question/Topic? 0
  • +

Replies To: MP3 Music Player

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: MP3 Music Player

Posted 02 March 2007 - 06:38 PM

Put a check into your code that makes it so that when the song is 100% loaded, call the code from the play button(I can't see it in what you supplied).
Was This Post Helpful? 0
  • +
  • -

#3 dabearunleashed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-February 07

Re: MP3 Music Player

Posted 03 March 2007 - 11:11 AM

i tried adding the play button actionscript, and changing the conditions to get the player to start when loaded. but now it wont even play EVEN when i press play LOL!

ahh man i dont know what im doin. i know i need an if/else, but i just cant get it right.

:angry:

heres what i got so far and the changes made ( // Play from start)



this.onEnterFrame = function () {
sload = mySound.getBytesLoaded();
stotal = mySound.getBytesTotal();
percentload = (Math.round((sload/stotal) * 100)) + "%";
if (counter < 2) {
counter = counter + 1;

// txt file telling where the mp3s are and there names.
loadVariablesNum("tracks.txt", 0);

// character to split track
songtitle = musictitle.split(":");
count2 = 0;
songplaying = (count2+1) + " - " + songtitle[count2];
}
if (stopped!=true) {
mySoundDuration=Math.round(_root.mySound.duration/1000);
mySoundPosition=Math.round(_root.mySound.position/1000);
texttime = mySoundPosition;
timemin = 0;
if (texttime < 10) {
	texttime = "0" + texttime;
}
while(texttime >= 60) {
	texttime = texttime - 60;
	timemin = timemin + 1;
if (texttime < 10) {
	texttime = "0" + texttime;
}
}
}
timeformat = timemin + ":" + texttime;

// Play from start
	if (counter = 100) {
		_root.mySound.stop();
		_root.mySound.start(mySoundPosition,0);
		stopped=false;
	} else {
		_root.mySound.stop();
		_root.mySound = new Sound();
		_root.mySound.loadSound(songtitle[count2],true);
		_root.mySound.start();
		stopped=false;
	}

//Rewind
if (REV==1 && mySoundPosition>0) {
	_root.mySound.stop();
	mySoundPosition=mySoundPosition-1;
	_root.mySound.start(mySoundPosition,0);
	}
revButton.onPress = function () {
	REV=1;
	mySoundPosition=Math.round(_root.mySound.position/1000);
	//
}
revButton.onRelease = function () {
	REV=0
}

//Fast Forward
if (FF==1 && mySound.position<mySound.duration) {
		_root.mySound.stop();
		mySoundPosition=mySoundPosition+1;
		_root.mySound.start(mySoundPosition,0);
	}
FFButton.onPress = function () {
	FF=1;
	mySoundPosition=Math.round(_root.mySound.position/1000);
}
FFButton.onRelease = function () {
	FF=0
}


}




please help me.

thanx

This post has been edited by dabearunleashed: 03 March 2007 - 11:13 AM

Was This Post Helpful? 0
  • +
  • -

#4 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: MP3 Music Player

Posted 03 March 2007 - 04:37 PM

Using = doesn't compare things; it assigns values to them. So you need to use ==.

Also, I can't see a point where you are getting counter to a point where it might equal 100. The highest I can ever see it becoming is 2, based on your conditional near the top of your code.

Here's a (untested) piece of sample code that might work to play your song when it is loaded. It tests whether the song is loaded before it calls your play code.

if(sload == stotal) {
	_root.mySound.stop();
	_root.mySound.start(mySoundPosition,0);
	stopped = false;
} else {
_root.mySound.stop();
_root.mySound = new Sound();
_root.mySound.loadSound(songtitle[count2],true);
_root.mySound.start();
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1