Not logged in. · Lost password · Register
Forum: Skins RSS
Playlist item ID recalc?
Avatar
Tom W.M. #1
Member since Feb 2003 · 40 posts · Location: La Crosse, WI, USA
Group memberships: Members
Show profile · Link to this post
I'm working on getting playlist sorting (by name, filename, etc.; also playlist randomizing and reversal) working in a skin I'm working on. My strategy is to sort an array of song rows (for speed reasons, the sorting is done with JavaScript's Array.sort() function), then loop through the array and remove every song from the playlist, and append each to the end of the playlist.  The current song is then moved down until it is in its proper position.

The following code is my function for creating the querystring passed to BrowseAmp.  It accepts an array, sorted, that contains the new playlist order.  Each element in the array has a property, row, which contains the row (a <tr/>) it corresponds to.  Each row (they were generated from an XML file with JavaScript) has a number of JavaScript properties--the ones relevant here are pl_path, which contains the path to the file, and pl_baid, which contains BrowseAmp's ID value for the playlist entry.

function pl_applyOrderArray(sorted) {
  var pltbody = document.getElementById("pltbody"); // the playlist table's <tbody> element
  var current = null; // the currently playing track--this has to be treated specially: it cannot be removed, because it might be playing
  var arg = ""; //the argument to be sent to BrowseAmp
  for (var i = 0; i < sorted.length; i++) {
   // pltbody.appendChild(sorted[i].row);
   if (sorted[i].row.pl_current) { // if it is the current row
    var current = sorted[i].row;
   } else { // non-current rows are removed and reinserted at the end
    arg += "removetrack=" + sorted[i].row.pl_baid + "&add=" + encodeURIComponent(sorted[i].row.pl_path) + "&";
   }
  }
  // move the current track down
  for (var i = 0; i < current.pl_index - 1; i++) {
   arg += "movedn=" + current.pl_baid + "&";
  }
  refreshPlaylist(arg,false); //the argument will be sent to BrowseAmp; "false" simply tells the function to fetch the entire playlist
};

My problem is that I get erratic results in Winamp when the querystring is sent.  Duplicates of some files appear, sometimes, and the order is sometimes wrong.  This happens to just a few files each time, but it kinda undermines a sorting function if the songs aren't actually sorted, doesn't it?  <_<

What I'm wondering is whether BrowseAmp is recalculating the IDs of playlist entries at some point--this would prevent them being deleted, and lead to the problem's I'm having.  Does adding songs do this?  Also, combining many movedn commands doesn't seem to work: the current playlist song doesn't move, but remains at the top of the playlist.

Thanks,
Tom W.M.
Avatar
Azimuth #2
Member since Jan 2003 · 427 posts · Location: Chicago, Illinois - USA
Group memberships: Members
Show profile · Link to this post
Have you tried the latest Winamp version (5.094)? I noticed there was a new version yesterday that fixed some other problems I was having.
Avatar
Tom W.M. #3
Member since Feb 2003 · 40 posts · Location: La Crosse, WI, USA
Group memberships: Members
Show profile · Link to this post
I just upgraded to the latest version of Winamp, but my problems continue.
Avatar
Tom W.M. #4
Member since Feb 2003 · 40 posts · Location: La Crosse, WI, USA
Group memberships: Members
Show profile · Link to this post
I've just realized that there is another problem with this technique: when movedn (or moveup) is used to reposition the current song, Winamp will leave whatever song takes the same playlist position highlighted like it is the current song.  Though the moved song continues to play, when it ends the song that was after it in its old position will be played next!  This means that, if a playlist is reordered with the function above, the second song in the playlist will be played after the current one, whatever its position.

Is there any way to get around this bug?  It's really a deal-killer (though I suppose that I could stop playback when the playlist is reordered).
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Page created in 180.6 ms (92.9 ms) · 53 database queries in 82.1 ms
Current time: 2018-12-18, 13:37:45 (UTC +00:00)