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: on_playback_pause not triggering at all (Read 745 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

on_playback_pause not triggering at all

Hi!

I'm attempting to write a component that updates a status with my currently playing song, and I want it to mention when I'm paused or just not say anything when the song is stopped. However, even with just a single console::printf statement in on_playback_pause, nothing ever gets printed to the console. on_playback_new_track works just fine, however on_playback_pause and on_playback_stop don't. My playback_handler code is here:

Code: [Select]
class playback_handler : public play_callback_static {

    char* curr_song = new char[1024];

    void on_playback_starting(play_control::t_track_command p_command, bool p_paused) {}
    void on_playback_stop(play_control::t_stop_reason p_reason) {
        update_song("");
    }
    void on_playback_seek(double p_time) {}
    void on_playback_time(double p_time) {}
    void on_playback_pause(bool p_state) {
        char buff[1024];
        snprintf(buff, sizeof(buff), "🎵 Paused: %s 🎵", curr_song);
        console::printf("%s", buff);
        update_song(buff);
    }
    void on_playback_edited(metadb_handle_ptr p_track) {}
    void on_playback_dynamic_info(const file_info& p_info) {}
    void on_playback_dynamic_info_track(const file_info& p_info) {}
    void on_volume_change(float p_new_val) {}

    unsigned get_flags() { return flag_on_playback_new_track; }
    void on_playback_new_track(metadb_handle_ptr p_track) {
        file_info_impl info;
        p_track->get_info(info);
        snprintf(curr_song, 1024, "%s by %s", info.meta_get("Title", 0), info.meta_get("Artist", 0));
        char buff[1024];
        snprintf(buff, sizeof(buff), "🎵 Listening To: %s 🎵", curr_song);
        console::printf("%s", buff);
        update_song(buff);
    }
};
static play_callback_static_factory_t<playback_handler> foo_playback;

Re: on_playback_pause not triggering at all

Reply #1
You need to combine the flags you want here..

Code: [Select]
unsigned get_flags() { return flag_on_playback_new_track; }

Fixed:

Code: [Select]
unsigned get_flags() { return flag_on_playback_new_track | flag_on_playback_pause | flag_on_playback_stop; }

Re: on_playback_pause not triggering at all

Reply #2
I figured it was something simple that I missed. Thank you so much! That works