Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone help me amend this xml mp3 player 1

Status
Not open for further replies.

suzisweet

Programmer
Aug 25, 2006
38
GB
Hi all,

I was hoping someone could help me amend this xml mp3 player I downloaded
from :


you can see my version ( smaller , no frills ) on here :


Now for what I want to do....

As you will see, to start the player you have to press the play button. Also,when the first song is finished it will not go on to the next song unless the user clicks on the skip button then clicks play.

I am trying to change the player so that it starts automatically when the site
loads and also continues to play subsequent songs unless actions are invoked from the stop , skip buttons etc.

I would really appreciate any help on this...

the mp3 player can be downloaded from the mike freidel link above. Then you can view the actionscript etc.

please anyone...i know that sounds desperate but i am, I have a deadline fast approaching and who better to help me but my fellow developers...

thanks in advance..

suzi
 
One thing at a time. To make it to start playing automatically, do the following:

1. Create a new function: for example "function playTune(){}"
2. Cut the contents of "play_btn.onRelease" function and paste it to the function above.
3. Assign "playTune()" to "play_btn.onRelease" function.

Now if you press "play_btn" it calls the function "playTune()", which does the same thing as before.

4. Add "playTune()" to the XML onLoad function so that it triggers playTune() when the XML is loaded. It will be at the end of "if (success) {}" statement inside of the function "ladeDaten(success) {}" function. (Is this in German?)

Hope this makes sense.

Kenneth Kawamoto
 
Thanks for getting back kenneth

i really appreciate your time and advice, I will look into what you said and will post a reply to let you know how I get on...

once again thanks

oh and yes i think it is in german

suzi
 
Hi Kenneth,

I am not an expert actionscript developer, im learning all the time though.

ok this problem...

im not quite sure how to amend the actionscript in the terms that you had spoke of previously.

here is my rather poor attempt of first of all creating the "function playTune(){}" by copying the contents of the
"play_btn.onRelease" . I then have attempted to assign the "function playTune(){}" to "play_btn.onRelease"

im really thinking im way out here though, here is the actionscript:

////////////////////////////////////////////////////////

function playTune(){
if (pauseSignal == true) {
MySound.start(pausePos, 0);
pauseSignal = false;
playSignal = true;
delete pausePos;
kugel_mc._visible = 1;
} else {
MySound = new Sound();
if (volstatus < volume) {
volume = volstatus;
} else if (volstatus > volume) {
volume = volstatus;
} else if (volstatus == 100) {
volume = 100;
}
if (balstatus < balance) {
balance = balstatus;
} else if (balstatus > balance) {
balance = balstatus;
} else if (balstatus == 0) {
balance = 0;
}
MySound.loadSound(AudioPath, StreamSignal);
MySound.setVolume(volume);
MySound.setPan(balance);
MySound.onSoundComplete=function(){
kugel_mc._visible = 0;
playSignal = false;
status = "Status: stopped";
}
volstatus = volume;
balstatus = balance;
pauseSignal = false;
playSignal = true;
wahlSignal = false;
_parent.onEnterFrame = function() {
total = MySound.getBytesTotal();
geladen = MySound.getBytesLoaded();
if (geladen != total) {
if (geladen != undefined && total != undefined) {
status = "Status: " + Math.round((geladen*100/total)) + "% loaded";
}
mc._xscale = Math.round((geladen*100/total));
} else {
status = "Status: 100% Loaded";
delete _parent.onEnterFrame;
kugel_mc._visible = 1;
if (!StreamSignal) {
MySound.start(pausePos, 0);
}
}
}
}
}


play_btn.onRelease = function playTune()

///////////////////////////////////////////////////

think im well off the right track here, would really appreciate some help.

the other thing is how do i write the script to add "function playTune(){}" to the XML onLoad function so that it triggers the player when the xml is loaded?

sorry for the big post,

thanks in advance for the help

suzi
 
Your "function playTune(){ ... }" bit is fine I think. But the "play_btn.onRelease" should be:
[tt]
play_btn.onRelease = function() {
playTune();
};
[/tt]
At this stage you should verify "play_btn" still works as before.

Kenneth Kawamoto
 

Hi KENNETH,

thanks for that

the only thing left for me to do is to add the 'function playTune()' to the XML onLoad, so that it plays the song as soon as the page loads.

problem is in not quite sure were to add it and what to write in the code below

if I could get this bit im sure it would work, ive tested the play button and it works fine so the only thing now is for the song1 to play as soon as the page loads

please can you help?

thanks in advance

the code is below


////////////////////////////////////////////////

data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.onLoad = ladeDaten;
data_xml.load(playlist);

function ladeDaten(success) {
if (success) {
aPath = new Array();
songTitel = new Array();
songArtist = new Array();
songCover = new Array();
audioTracks = new Array();
audioTracks = this.firstChild.childNodes;
totalAudio = audioTracks.length;
for (var i=0; i<totalAudio; i++) {
if (audioTracks.nodeName == "song") {
aPath.push(audioTracks.attributes.path);
songTitel.push(audioTracks.attributes.title);
songArtist.push(audioTracks.attributes.artist);
songCover.push(audioTracks.attributes.bild);
}
}
AudioPath = aPath[0];
titel = songTitel[0];
artist = songArtist[0];
aktAudio = 1;
trackAnzeige = aktAudio+" / "+totalAudio;
status = "Status: playlist - Loaded";
if (playerlook) setCover(0);
erstesBild = true;
} else {
status = "Status: PlayList - Not loaded";
}
delete audioTracks;
delete data_xml;
}

 
got the mp3 player to play the first song as soon as the page loads. added the ' playTune();' to the bottom of the xml load on success bit :

///////////////////////////////////////

function ladeDaten(success) {
if (success) {
aPath = new Array();
songTitel = new Array();
songArtist = new Array();
songCover = new Array();
audioTracks = new Array();
audioTracks = this.firstChild.childNodes;
totalAudio = audioTracks.length;
for (var i=0; i<totalAudio; i++) {
if (audioTracks.nodeName == "song") {
aPath.push(audioTracks.attributes.path);
songTitel.push(audioTracks.attributes.title);
songArtist.push(audioTracks.attributes.artist);
songCover.push(audioTracks.attributes.bild);
}
}
AudioPath = aPath[0];
titel = songTitel[0];
artist = songArtist[0];
aktAudio = 1;
trackAnzeige = aktAudio+" / "+totalAudio;
status = "Status: playlist - Loaded";
if (playerlook) setCover(0);
erstesBild = true;
playTune();


///////////////////////////////////////////////////////

this just gets more frustrationg though.....

ok it plays the first song automatically, but when the first song finishes the mp3 player stops and doesnt go on to play the second song

any ideas what i can do?

sorry to keep throwing these questions at you but you have helped me out a lot so far and i do appreciate it,

thanks in advance

suzi
 
This one will be very similar to the first one, if a little bit more complicated.

1. Create a new function, for example "function playNext(){}".
2. Cut the contents of the function "next_btn.onRelease" and paste it to the function "playNext()".
3. Put "playNext()" as the contents of the function "next_btn.onRelease".

Now it's time to verify "next_btn" still works as before. Do you notice it loads the next tune but it doesn't start playing? The original coder had funny idea about how the music player should work! Anyway you want the next tune starts playing immediately without having to press the "play" button.

4. Put "playTune()" at the end of the contents of the function "playNext()"

Now if you press "next" button it will load and play the next tune.

The next task is to fire the "playNext()" when the current tune finishes.

5. Put this at the end of the contents of the function "playTune()", so that when "MySound" reaches the end "playNext()" is triggered:
[tt]
MySound.onSoundComplete = function() {
playNext();
};
[/tt]
Hope you can follow this.

Kenneth Kawamoto
 
hi kenneth,

hope you are well.

many thanks for your help a couple of weeks ago, as i said the player is working well, however there is one final thing which im trying to fix.

when the player finishes playing the last song it just stops. It does not loop back to the first song.

any idea what i could do? the actionscript amendments you gave me last time worked a treat, any similar solutions this time would be much appreciated.

hope you can help...

thanks for now,

suzi
 
Suzi, that should be fairly easy, but I no longer have your code. Can you post it here? I only need the contents of "function playNext()" - you don't have to copy and paste everything.

Kenneth Kawamoto
 
hi kenneth,

thanks for getting back.

here is the code for the play next function :

/////////////////////////////////////////////////

function playNext(){
if (aktAudio<totalAudio) {
aktAudio += 1;
AudioPath = aPath[aktAudio-1];
titel = songTitel[aktAudio-1];
artist = songArtist[aktAudio-1];
MySound.stop();
playSignal = 0;
pauseSignal = 0;
wahlSignal = 1;
delete pausePos;
kugel_mc._visible = 0;
trackAnzeige = aktAudio+" / "+totalAudio;
status = "Status: stopped - press play";
setCover(aktAudio-1);
playTune();
}
}

////////////////////////////////////////////////////////

just incase here is the play tune function and the load xml part.


playTune :

/////////////////////////////////////////

function playTune(){
if (pauseSignal == true) {
MySound.start(pausePos, 0);
pauseSignal = false;
playSignal = true;
delete pausePos;
kugel_mc._visible = 1;
} else {
MySound = new Sound();
if (volstatus < volume) {
volume = volstatus;
} else if (volstatus > volume) {
volume = volstatus;
} else if (volstatus == 100) {
volume = 100;
}
if (balstatus < balance) {
balance = balstatus;
} else if (balstatus > balance) {
balance = balstatus;
} else if (balstatus == 0) {
balance = 0;
}
MySound.loadSound(AudioPath, StreamSignal);
MySound.setVolume(volume);
MySound.setPan(balance);
MySound.onSoundComplete=function(){
playNext()
kugel_mc._visible = 0;
playSignal = true;
status = "Status: stopped";
}
volstatus = volume;
balstatus = balance;
pauseSignal = false;
playSignal = true;
wahlSignal = false;
_parent.onEnterFrame = function() {
total = MySound.getBytesTotal();
geladen = MySound.getBytesLoaded();
if (geladen != total) {
if (geladen != undefined && total != undefined) {
status = "Status: " + Math.round((geladen*100/total)) + "% loaded";
}
mc._xscale = Math.round((geladen*100/total));
} else {
status = "Status: 100% Loaded";
delete _parent.onEnterFrame;
kugel_mc._visible = 1;
if (!StreamSignal) {
MySound.start(pausePos, 0);
MySound.onSoundComplete = function() {
playNext();
}
}
}
}
}
}

////////////////////////////////////////



load xml :

////////////////////////////////////////

data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.onLoad = ladeDaten;
data_xml.load(playlist);

function ladeDaten(success) {
if (success) {
aPath = new Array();
songTitel = new Array();
songArtist = new Array();
songCover = new Array();
audioTracks = new Array();
audioTracks = this.firstChild.childNodes;
totalAudio = audioTracks.length;
for (var i=0; i<totalAudio; i++) {
if (audioTracks.nodeName == "song") {
aPath.push(audioTracks.attributes.path);
songTitel.push(audioTracks.attributes.title);
songArtist.push(audioTracks.attributes.artist);
songCover.push(audioTracks.attributes.bild);
}
}
AudioPath = aPath[0];
titel = songTitel[0];
artist = songArtist[0];
aktAudio = 1;
trackAnzeige = aktAudio+" / "+totalAudio;
status = "Status: playlist - Loaded";
if (playerlook) setCover(0);
erstesBild = true;
playTune();

} else {
status = "Status: PlayList - Not loaded";
}
delete audioTracks;
delete data_xml;
}

///////////////////////////////////////////////

thanks again,

suzi

 
This is just a guess, if it doesn't work let me know (sure you will!)
Code:
function playNext(){
   aktAudio < totalAudio ? aktAudio++ : aktAudio = 1;
   AudioPath = aPath[aktAudio-1];
   titel = songTitel[aktAudio-1];
   artist = songArtist[aktAudio-1];
   MySound.stop();
   playSignal = 0;
   pauseSignal = 0;
   wahlSignal = 1;
   delete pausePos;
   kugel_mc._visible = 0;
   trackAnzeige = aktAudio+" / "+totalAudio;
   status = "Status: stopped - press play";
   setCover(aktAudio-1);
   playTune();
}

Kenneth Kawamoto
 
yet again kenneth your wisdom has prevailed !

that works a treat. The player now loops back to the first song.

what is it in the code you provided that does this?

i take it , it isnt dependent on there being a specific number of songs i.e. will it work with 3 songs or 20 songs the same way.

thanks again, let me know how you did it..

much appreciated !

suzi
 
Yes it will work with any number of songs. The trick is very simple, it's all in the first line. If the song ID ("aktAudio") goes beyond the number of songs it reverts back to 1. That's all!

Kenneth Kawamoto
 
Hey Kenneth how are you, hope you are well.

Thanks again for the all the help recently.

Im trying to do something which i think should be fairly simple. Im trying to add links , just normal hyperlinks in the content of my XML based news.

not sure how to create links in XML tho. You can view what i mean here, there are links which are currently unactive in the content of my news text.

here is the link.


once again any help would be much appreciated - thanks in advance

suzi
 
thanks for the reply kenneth,

problem is ive used XML throughout already, here is a sample of the code:

<kungfu>
<heading>Tarbert Music Festival</heading>
<monkey>------------------------------------------------------------
Scott will be playing this years Tarbert music festival with
the Lynsey Dolan Band. The event takes place on the weekend
of the 15th-17th of September. For more details check out
<space>-----------------------------------------------------------</space>
</kungfu>

i want the " to be a clickable link but, to use a scottish phrase;, its doin ma' nut in !

There must be a simple amendment to the code above that could achieve this surely?

do you deal much with XML Kenneth?

thanks again in advance

suzi
 
got it to work, took your advice and amended my text area component to HTML true , then changed the code using <a> tags.

thanks again kenneth

suzi
 
Yes I do XML all the time. There are two ways:

1. Use CDATA. In XML, anything inside CDATA is parsed as it is.
[tt]
<monkey><![CDATA[Scott will be playing this years Tarbert music festival with the Lynsey Dolan Band. The event takes place on the weekend of the 15th-17th of September. For more details check out <a href='www.myspace.com/thelynseydolanband</a>.]]></monkey>
[/tt]

2. (My way) Use [] (square bracket) in XML and substitute them with <> (angle bracket) in Flash.
[tt]
<monkey>Scott will be playing this years Tarbert music festival with the Lynsey Dolan Band. The event takes place on the weekend of the 15th-17th of September. For more details check out [a href=']www.myspace.com/thelynseydolanband[/a].</monkey>
[/tt]

Caveat: Flash TextFields cannot deal with URL links which have more than 127 characters. If your URL is very long, you must use "asfunction".

Do you actually have nuts?

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top