play track from playlist via command line

I'm writing a web interface for mocp and I'd like to mimic the playlist functionality where you can add tracks to a playlist and then click on a track in the playlist and moc will jump to that track. Next would then go to the next track, and previous the previous track. (As in the console version). I can't seem to figure out how to do this...I can get the track to play via the playit command but then next goes back to the track that was after the track that was playing before the playit command. Is there anyway to do this?

Not without patching, I'm afraid. "Playit" doesn't modify the playlist (so doesn't change the server's internal queue), so it would be used if you wanted to fire off one music file besides your playlist.

If you want MOC to stop playing at the end of the selected track, then just setting AutoNext off should suffice.

If you want MOC to go on to the next track on your mimicking playlist, then you're out of luck because MOC doesn't know anything about that playlist.

If you made use of a native MOC playlist instead of trying to mimic it, you might have more luck (although a quick test suggests playing will just stop after the selected track).

Thanks for the responses. My plan is to populate the moc playlist so it matches the web playlist. The problem is if they click on a track in the web playlist there's no easy way to tell moc to play a track in the middle of its playlist. I think I have a solution though. When they click a track in the web playlist I'll just clear the moc playlist and add all the tracks from that track on to moc's playlist. Then it will go to the next track. It doesn't matter that moc doesn't know about previous tracks as it's only going forward.

Well my plan is to poll the server using mocp -i

Yes, that should work.

One alternative would be to use the queue (with a suitable setting for the QueueNextSongReturn configuration option). Another would be to query MOC and then move it forwards or backwards in the playlist from there (although that might introduce brief intra-track artifacts).

But those suggest some new command line options might be useful: go to playlist track number, clear queue, and advance 'n' entries in the queue.

Thanks for the response. If we're adding new command line options I think an option to playit along the lines of "if this item is in the playlist then move the playlist position to this item" would suffice. Cheers.

When I use -a to add tracks to the playlist, moc seems to sort them. Is there a way to disable this sorting so they appear in the order they are sent to moc?