Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: How to force the calling order ? (Read 3664 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How to force the calling order ?

I have a function:

Code: [Select]
void func(){
    // initialization ignored ...

    static_api_ptr_t<play_control>()->start(play_control::track_command_next);
    static_api_ptr_t<playlist_manager> ()->playlist_remove_items(list_idx, bit_array_one(item_idx));
}

When the function is called, foobar2k always removes the song before playing the next one.
This would lead to the "wrong" next song to be played.


I also tried a callback on starting, which, however, makes foobar2k crash...

Code: [Select]
// in a class named RemoveCallBack:
void on_playback_starting(play_control::t_track_command p_command,bool p_paused) {
    static_api_ptr_t<playlist_manager> list;
    list->playlist_remove_items(list_idx, bit_array_one(item_idx));
    static_api_ptr_t<play_callback_manager>()->unregister_callback(this);
}

// the previous func
void func(){
    // initialization ignored ...

    static_api_ptr_t<play_callback_manager>()->register_callback(
        new service_impl_t<RemoveCallBack>,
        play_callback::flag_on_playback_starting,
        false
    );
    static_api_ptr_t<play_control>()->start(play_control::track_command_next);
}

How can I force foobar2k to play the next song before removing a specific song from the playlist?

Thanks.

How to force the calling order ?

Reply #1
Verify in the SDK comments whether it's legal to modify the playlist while in a play callback.
If it's forbidden, which it probably is, you can register a main_thread_callback from there, and do your operation inside of that.

In particular, it may be illegal to unregister a callback from inside itself. Yet another case where a main_thread_callback helps.
Stay sane, exile.

How to force the calling order ?

Reply #2
Verify in the SDK comments whether it's legal to modify the playlist while in a play callback.
If it's forbidden, which it probably is, you can register a main_thread_callback from there, and do your operation inside of that.

In particular, it may be illegal to unregister a callback from inside itself. Yet another case where a main_thread_callback helps.

Yes, you're right. It's the unregister-self behavior that crashes foobar2k.

I've followed your advice and unregistered the callback successfully.
But... foobar2k still removes the song before starting to play the next one,
which is opposite to my expectation and causes the "wrong" next song to play.
That really confuses me.

Is there any other way to get the thing done:
Start playing the next song in the current playing order first, and then remove the previous one from the playlist ?

Thank you.

How to force the calling order ?

Reply #3
Playlist modifications happen synchronously, whereas the playback start request is processed asynchronously. One way to achieve the desired result might be to use the playback queue. You could add the track to the queue using its playlist position, start playback and remove the song from the playlist. Of course you would also have to worry about the state of the playback queue, i.e. whether it is empty. I think that is how I handled it in foo_utils.

How to force the calling order ?

Reply #4
Playlist modifications happen synchronously, whereas the playback start request is processed asynchronously. One way to achieve the desired result might be to use the playback queue. You could add the track to the queue using its playlist position, start playback and remove the song from the playlist. Of course you would also have to worry about the state of the playback queue, i.e. whether it is empty. I think that is how I handled it in foo_utils.

Very impressive... You know really a lot! Are you the author of foobar2k?

Your method works very good, however, except one thing:
It seems that I have to decide the next song myself.

Any way to know which song is the next to play in the current playing order (without actually playing it) ?

Thank you.

 

How to force the calling order ?

Reply #5
Very impressive... You know really a lot! Are you the author of foobar2k?


No, foosion worked on some portions of the player. Another person did the rest, etc...



How to force the calling order ?

Reply #8
Yeah, what the others said. I have been around since about 2002 as a foobar2000 user, plugin author, forum moderator and alpha tester. I have contributed some parts to foobar2000 and the SDK, and was sometimes mistaken for being its author. ;-) My most active time was until 2006/2007. Since then life, work and other interests have taken their toll on the time I spend on foobar2000 and my knowledge of the SDK is getting hazy. I still try to help new developers to get started with the SDK which has become significantly more complex in the past nine years.

Hm, I think I should put this text on my profile page here on the forum. :-)