I'm writing a plugin which requires knowing what track will get played next.
The ultimate goal is to be able to have pre-specified tracks always played together in the correct order. Think Queen's "We Will Rock You" and "We Are The Champions". If your album happens to split the songs up, but they are supposed to be played together, it can be a bit annoying that shuffle always separates them.
So far I have the logic and everything in place so that when Foobar selects "We Will Rock You", it adds "We Are the Champions" to the playlist queue. But, say if "Werewolves In London" was supposed to follow "We Will Rock You", I want that to then come after "We Are The Champions", instead of "Dark Chest of Wonders"
That desired behavior happens automatically when I add songs to the queue with
pm->queue_add_item(playlist, songHandle);
But when doing it with
pm->queue_add_item_playlist(playlist, songIndex);
the playlist continues from wherever "We Are The Champions" would have been according to the play order. I want to use the latter so that it I can see them queue on the playlist, and I can choose to dequeue. In order to do that, I would need to know which track comes next.
From my playing around, it seems the only option would be do something like this:
metadb_handle_ptr last_played_handle;
static_api_ptr_t<playlist_manager> pm;
static_api_ptr_t<play_control> pc;
// check if the last song played was one "We Will Rock You" or "We Are The Champions"
if(last_played_handle.is_empty()){
metadb_handle_ptr temp_handle;
pc->get_now_playing(temp_handle);
// if not, check if this song is one of them
if(mdb->path_compare_metadb_handle(song1, temp_handle) || mdb->path_compare_metadb_handle(song2, temp_handle)){
last_played_handle = temp_handle;
pc->start(playback_control::track_command_next, false);
}
return;
}
pc->get_now_playing(song3);
t_size song1index = 0;
t_size song2index = 0;
t_size song3index = 0;
t_size playlist = pm->get_active_playlist();
//get playlist index for all 3 songs...Is there a more efficient method? I don't like this at O(n)
pm->playlist_find_item(playlist, song1, song1index);
pm->playlist_find_item(playlist, song2, song2index);
pm->playlist_find_item(playlist, song3, song3index);
//enqueue all 3 songs
pm->queue_add_item_playlist(playlist, song1index);
pm->queue_add_item_playlist(playlist, song2index);
pm->queue_add_item_playlist(playlist, song3index);