11

How to set up a select playlist in jQuery

 3 years ago
source link: https://www.codesd.com/item/how-to-set-up-a-select-playlist-in-jquery.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to set up a select playlist in jQuery

advertisements

I am making a simple music playing online app. I would like to make a song playlist, and I would like the songs in the playlist to be sortable. I plan to use the jQuery "sortable" plugin. However, I would like to keep track of what order the songs are in, so that when one song finishes, I know which song to start next. Instead of creating an event handler to be executed when the user changes the order of the songs, and actually keeping track of what order songs are in, my current solution is simply this:

  1. Keep track of the id of the currently playing song element
  2. When the song finishes, use jQuery to find the element with the current id
  3. Use .next() to get the next song to play

Is there anything wrong with this implementation? Would it be better to constantly keep track of the order of songs?


Seems entirely appropriate and I actually use that exact same approach on a completely unrelated website. Here is what I do to get the next id, I know you said you already had something working but I thought I'd share anyways in case it helps:

current_id = window.my_id;
next_id = $('#' + current_id).next().attr('id');

if (next_id == undefined) {
    return; // no more siblings after it
}

// do what you need to do here with next_id to actually load the next content
// in my web apps case, it removes some elements and just changes the hash
// which another function handles

current_id = next_id;
window.my_id = current_id;




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK