IPB

Welcome Guest ( Log In | Register )

> foobar2000 Development Forum Rules

This forum is for developer discussions only. If you have a problem / bug report / idea / feature request that isn't related to foobar2000 SDK, post it in an appropiate forum instead - tech support questions go to support forum, everything else goes to general forum.
All non-developer posts on this forum will be removed. Continued abuse of this forum will result in admin actions (warnings, account suspension).

 
Reply to this topicStart new topic
How to force the calling order ?
lowzoom
post Nov 2 2011, 10:59
Post #1





Group: Members
Posts: 10
Joined: 31-October 11
Member No.: 94819



I have a function:

CODE
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
// 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.

This post has been edited by db1989: Nov 4 2011, 18:28
Reason for edit: Please use the standard font size for normal text, not an enlarged one.
Go to the top of the page
+Quote Post
Zao
post Nov 2 2011, 12:25
Post #2





Group: Members (Donating)
Posts: 899
Joined: 25-September 03
From: Umeň, Sweden
Member No.: 9001



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.

This post has been edited by Zao: Nov 2 2011, 12:25


--------------------
Zao shang yong zao nong zao rang zao ren zao.
To, early in the morning, use a chisel to build a bathtub makes impatient people hot-tempered.
Go to the top of the page
+Quote Post
lowzoom
post Nov 2 2011, 13:44
Post #3





Group: Members
Posts: 10
Joined: 31-October 11
Member No.: 94819



QUOTE (Zao @ Nov 2 2011, 12:25) *
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.
Go to the top of the page
+Quote Post
foosion
post Nov 2 2011, 14:12
Post #4





Group: FB2K Moderator (Donating)
Posts: 4409
Joined: 24-February 03
Member No.: 5153



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.


--------------------
http://foosion.foobar2000.org/ - my components for foobar2000
Go to the top of the page
+Quote Post
lowzoom
post Nov 2 2011, 16:34
Post #5





Group: Members
Posts: 10
Joined: 31-October 11
Member No.: 94819



QUOTE (foosion @ Nov 2 2011, 14:12) *
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.

This post has been edited by lowzoom: Nov 2 2011, 16:45
Go to the top of the page
+Quote Post
mudlord
post Nov 4 2011, 09:39
Post #6





Group: Developer (Donating)
Posts: 805
Joined: 1-December 07
Member No.: 49165



QUOTE (lowzoom @ Nov 2 2011, 09:34) *
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...
Go to the top of the page
+Quote Post
lowzoom
post Nov 4 2011, 16:03
Post #7





Group: Members
Posts: 10
Joined: 31-October 11
Member No.: 94819



QUOTE (mudlord @ Nov 4 2011, 09:39) *
QUOTE (lowzoom @ Nov 2 2011, 09:34) *
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...

So maybe I should call him one of the authors ?
Go to the top of the page
+Quote Post
db1989
post Nov 4 2011, 18:26
Post #8





Group: Super Moderator
Posts: 5275
Joined: 23-June 06
Member No.: 32180



foosion contributed to foobar2000 itself between 2005 and 2006, but has been more active in creating various components for it and maintaining the tutorials for others interested in doing so; hence, no doubt, his knowledge of its inner workings.
Go to the top of the page
+Quote Post
foosion
post Nov 4 2011, 19:07
Post #9





Group: FB2K Moderator (Donating)
Posts: 4409
Joined: 24-February 03
Member No.: 5153



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. :-)


--------------------
http://foosion.foobar2000.org/ - my components for foobar2000
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 25th July 2014 - 07:52