Skip to main content


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: Beginner playback_state question (Read 469 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Beginner playback_state question

Hi, I am trying to implement the following feature: When starting to play a song, it starts at a random part in the song. This is similar to this old Preview component except I want to be able to accept random values, not just a fixed second/percentage value.

So first of all, I took the foo_sample component and am just modifying it to test things out as I am very new. I tried implementing my feature within a context menu command, which works perfectly.
Code: (myPlaybackFunction) [Select]
playback_control::ptr pbc = playback_control::get();
double songLength = pbc->playback_get_length();
double randomTime = rand() % (int)songLength;

However, I want to be able to do this automatically (eventually add a toggle feature too). So I added this code into playback_state.cpp (CPlaybackStateDemo class). This is the big part which is confusing me. I have tried putting the above code (and some variants) into:
  • on_playback_starting, on_playback_new_track, on_playback_pause, etc.
  • update
  • a function, and then using
    Code: [Select]
    void on_playback_pause(bool p_state)
    std::function<void()> test1 =
but can't seem to get anything to work. From what I can tell, CPlaybackStateDemo inherits from play_callback_impl_base which registers itself on construction, yet I can't seem to get any calls to do anything. To be honest I have no idea where to go from here. Not sure if I'm missing something simple or if I need a much larger understanding of the foundation for this. I'm new to C++ (mostly a C# background). Any help would be appreciated, thanks.

P.S. I use Visual Studio to compile everything and was wondering if there was a nice way to debug. I've been building and then using the component, testing everything manually.

Re: Beginner playback_state question

Reply #1
I think that foo_sample code will only run when the dialog is open. You want your own class derived from play_callback_static

Code: [Select]
class MyClass: public play_callback_static
    uint32_t get_flags() override
         // take care to return the flags for the callbacks you intend to use.

   // all other overrides go here


As for debugging, I generally setup a junction from the VS output folder to a folder inside the user-components folder of a portable install. From an administrator command prompt, I might do something like..

Code: [Select]
mklink /D z:\foobar2000\profile\user-components\foo_sample z:\git\foobar2000-sdk\foobar2000\foo_sample\Release

Then inside VS itself, to to the Properties of your project>Debugging>Command and set it to the foobar instance above - in my case z:\foobar2000\foobar2000.exe

Also, make sure the project is set as the "startup project", Right click in solution explorer>set as startup project.

Re: Beginner playback_state question

Reply #2
That did it! The debug tip also helped a bunch and I will be working toward my toggle now. Thank you very much!

SimplePortal 1.0.0 RC1 © 2008-2021