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:
- Keep track of the id of the currently playing song element
- When the song finishes, use jQuery to find the element with the current id
- 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: