Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Forums

/

Add/Read Additional information from xml playlist

5 replies [Last post]

I'd like to add links into my playlist, the number of links will range from 1-5. Below is a sample from my xml file as well as my current javascript code for building my playlist. I can't seem to reference the links in my playlist. Any ideas would be greatly appreciated, Thanks!

XML >>

<?xml version="1.0" encoding="utf-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track>
<title>Alaska‘s Martin Creek</title>
<creator>Near Wrangell, Alaska this small clear stream can be a very productive steelhead river. Coeur D‘Alene‘s Joe Roope has been fishing this Creek for nearly 20 years and joins us on this episode. This winter buck was caught and released less than a mile from saltwater.</creator>
<location>JoeW.flv</location>
<image>videos/JoeStill.jpg</image>
<flies>
<fly title="Egg-Sucking Leech">fly_recipes_test.htm?item=2</fly>
<fly title="Electric Leech">fly_recipes_test.htm?item=3</fly>
<fly title="Frank‘s Fly">fly_recipes_test.htm?item=5</fly>
</flies>
</track>
</trackList>
</playlist>

JAVASCRIPT >>

function printPlaylistData() {
var plst = null;
plst = player.getPlaylist();
if (plst) {
var txt='<table cellPadding="0" cellSpacing="8" border="0" width="298">';
for(var i in plst) {
txt+='<tr><td><table width="288" cellPadding="0" cellSpacing="0" id="itm' + i + '" onclick="if(! linkFlag) player.sendEvent(\'ITEM\',' + i + ');" ';
txt+='class="playlistlo" onmouseover="mover(this, ' + i + ')" onmouseout="mout(this, ' + i + ')">';
txt+='<tr><td><img src="' + plst[i].image + '" width="140" height="79" title="Click to Play"></td>';
txt+='<td onMouseover="ddrivetip(\'' + plst[i].author + '\',\'#211719\', 200)"; onMouseout="hideddrivetip()" class="plst_pad" width="100%">';
txt+='<b>' + plst[i].title + '</b><br>';
//the next 3 lines are where i'm trying to access the link names and paths and display them in the playlist. I also need a loop before them to check how many there are.
//txt+='<a href="' + plst[i].link + '" target="_blank" title="' + plst[i].link + '" onclick="linkFlag=true"> fly 1</a><br>';
//txt+='<a href="' + plst[i].link + '" target="_blank" title="' + plst[i].link + '" onclick="linkFlag=true"> fly 2</a><br>';
//txt+='<a href="' + plst[i].link + '" target="_blank" title="' + plst[i].link + '" onclick="linkFlag=true"> fly 3</a><br>';

txt+='</td></tr></table></td></tr>';
}
txt+='</table>'; //alert(txt);

var tmp = document.getElementById("plstDat");
if (tmp) { tmp.innerHTML = txt; }
} else {
setTimeout("printPlaylistData()",100);
}
}

Use the meta element:

<?xml version="1.0" encoding="utf-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
  <trackList>
    <track>
      <title>Alaska‘s Martin Creek</title>
      <creator>Near Wrangell, Alaska this small clear stream can be a very productive steelhead river. Coeur D‘Alene‘s Joe Roope has been fishing this Creek for nearly 20 years and joins us on this episode. This winter buck was caught and released less than a mile from saltwater.</creator>
      <location>JoeW.flv</location>
      <image>videos/JoeStill.jpg</image>
      <meta rel='fly1link'>fly_recipes_test.htm?item=2</meta>
      <meta rel='fly1title>Egg-Sucking Leech</meta>
      <meta rel='fly2link'>fly_recipes_test.htm?item=3</meta>
      <meta rel='fly2title>Electric Leech</meta>
      <meta rel='fly3link'>fly_recipes_test.htm?item=5</meta>
      <meta rel='fly3title>Frank‘s Fly</meta>
    </track>
  </trackList>
</playlist>
var playlist = player.getPlaylist();
var fly1link = playlist[0]['fly1link'];
var fly1title = playlist[0]['fly1title']

Here's how you iterate through a multi-track playlist:

      function dumpPlaylist()
      {
        playlist = player.getPlaylist();
        var listnodes = '<br />';

        for(var j in playlist)
        {
          listnodes += '<br />Track: ' + j + '<br />';

          for(var k in playlist[j])
          {
            listnodes += '<li>' + k + ': ' + playlist[j][k] + '</li>';
          }
        }
        gid('playlist').innerHTML = '<br />Playlist:' + listnodes;
      };

still a little muddy how you're accesing fly1link and fly1title in your javascript.

txt += '<a href="' + plst[i].<strong>flv1link</strong> + '" target="_blank" title="' + plst[i].<strong>flv1title</strong> + '" onclick="linkFlag=true"> fly 1</a><br>';

I haven't tested this, but this is about where I would start:

    <script type="text/javascript">
      var player    =  null;
      var playlist  =  null;

      function playerReady(obj)
      {
        player = gid(obj.id);
      };

      function printPlaylistData()
      {
        playlist = player.getPlaylist();

        if(playlist.length > 0)
        {
          var txt  = '<table cellPadding="0" cellSpacing="8" border="0" width="298">'; 

          for(var j in playlist)
          {
            for(var k in playlist[j])
            {
              txt += '<tr><td><table width="288" cellPadding="0" cellSpacing="0" id="itm' + k + '" onclick="if(! linkFlag) player.sendEvent(\'ITEM\',' + k + ');" ';
              txt += 'class="playlistlo" onmouseover="mover(this, ' + k + ')" onmouseout="mout(this, ' + k + ')">';
              txt += '<tr><td><img src="' + playlist[j][k].image + '" width="140" height="79" title="Click to Play"></td>';
              txt += '<td onMouseover="ddrivetip(\'' + playlist[j][k].author + '\',\'#211719\', 200)"; onMouseout="hideddrivetip()" class="playlist_pad" width="100%">';
              txt += '<b>' + playlist[j][k].title + '</b><br>';
              if(playlist[j][k].fly1link) txt += '<a href="' + playlist[j][k].fly1link + '" target="_blank" title="' + playlist[j][k].fly1title + '" onclick="linkFlag=true"> fly 1</a><br>';
              if(playlist[j][k].fly2link) txt += '<a href="' + playlist[j][k].fly2link + '" target="_blank" title="' + playlist[j][k].fly2title + '" onclick="linkFlag=true"> fly 1</a><br>';
              if(playlist[j][k].fly3link) txt += '<a href="' + playlist[j][k].fly3link + '" target="_blank" title="' + playlist[j][k].fly3title + '" onclick="linkFlag=true"> fly 1</a><br>';
              if(playlist[j][k].fly4link) txt += '<a href="' + playlist[j][k].fly4link + '" target="_blank" title="' + playlist[j][k].fly4title + '" onclick="linkFlag=true"> fly 1</a><br>';
              if(playlist[j][k].fly5link) txt += '<a href="' + playlist[j][k].fly5link + '" target="_blank" title="' + playlist[j][k].fly5title + '" onclick="linkFlag=true"> fly 1</a><br>';
            }
          txt += '</td></tr></table></td></tr>';
          }

          txt += '</table>';

          var tmp = document.getElementById('playlistDat');

          if(tmp)
          {
            tmp.innerHTML = txt;
          }
        }
        else
        {
          setTimeout("printPlaylistData()", 100);
        }
      };
    </script>

Thanks lost, debugging it right now... seems to have trouble with this line: if(playlist[j][k].fly1link), looks like playlist[j][k] is undefined.

Hmmm...

Brain was disengaged.

playlist[j].fly1link

or

playlist[j]['fly1link']

I missed a single quote after all of the flytitles:

<?xml version="1.0" encoding="utf-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
  <trackList>
    <track>
      <title>Alaska‘s Martin Creek</title>
      <creator>Near Wrangell, Alaska this small clear stream can be a very productive steelhead river. Coeur D‘Alene‘s Joe Roope has been fishing this Creek for nearly 20 years and joins us on this episode. This winter buck was caught and released less than a mile from saltwater.</creator>
      <location>JoeW.flv</location>
      <image>videos/JoeStill.jpg</image>
      <meta rel='fly1link'>fly_recipes_test.htm?item=2</meta>
      <meta rel='fly1title'>Egg-Sucking Leech</meta>
      <meta rel='fly2link'>fly_recipes_test.htm?item=3</meta>
      <meta rel='fly2title'>Electric Leech</meta>
      <meta rel='fly3link'>fly_recipes_test.htm?item=5</meta>
      <meta rel='fly3title'>Frank‘s Fly</meta>
    </track>
  </trackList>
</playlist>