tags:

views:

312

answers:

4

While trying to integrate Yahoo Media Player into my own website, I want to allow users to click on a link to add the clicked track to the playlist. YMP API has got a function for doing that (http://mediaplayer.yahoo.com/api/#method_addTracks). It takes a DOM element. Now how should I pass the dom element. My code looks like this right now: ...

<li id="track1">
<a href="location of track" style="display:none">track1</a>
<a href="#" onclick="YAHOO.MediaPlayer.addTracks(WHAT SHOULD I PUT HERE?, null, true);">Add this to the playlist</a>
</li>

if anyone has worked with YMP or has any idea about this please help.

+1  A: 

You should place a reference to the DOM element you want to add, most likely by id like so:

<li id="track1">
<a id="trackelement" href="location of track" style="display:none">track1</a>
<a href="#" onclick="YAHOO.MediaPlayer.addTracks(document.getElementById('trackelement'), null, true);">Add this to the playlist</a>
</li>
Aron Rotteveel
I tried that too but for some reasons it's not working. Is document.getElementByID() browser specific. I tried to see the output with alert(document.getElementByID('trackelement')) but nothing returns
Java script is case sensitive so use getElementById instead of getElementByID
Glenn
And did you catch that Aron's example had the id attribute for the anchor tag?
Glenn
sorry for the capital case. Yes, I caught id attribute but I don't have any luck still.
Any js errors appear or something? Try to execute this script in console (Firebug)
aivarsak
+1  A: 

As far as I understand from the API page, you should be using

YAHOO.MediaPlayer.addTracks(document.getElementById('track1'), null, true);

(the documentation says "HTML DOM element (possibly contains media anchor tags)")

Alexander Gyoshev
Yeah that was true. I finally figure that out (hit and trial). Anyway thanks for your answer.
A: 

i finally solved this. this is what i did

<div id="debug"><a href="http://www.radioreloaded.com/audio/7k/6724_Akela Hoon Main.mp3">Akela hoon Mein, Raeth</a></div>

<a href="#" onclick="YAHOO.MediaPlayer.addTracks(document.getElementById("debug"),null,true);">Add to playlist</a>

to start playing the track you can

YAHOO.MediaPlayer.play();
A: 

If you have 10 tracks, how can you specify to play track 4 to YAHOO.MediaPlayer.play() ?

david alimian