Skip to main content
Topic: playback_control problem (Read 3482 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

playback_control problem

I'm trying to write some general purpose plugin, i only need start playing the current song and seek at specified position after fb2k start. So i tryed this code

Code: [Select]
class initquit_foobarstarter : public initquit
{
    void on_init();
    void on_quit();
};    

void initquit_foobarstarter::on_init()
{
    static_api_ptr_t<playback_control> pc;    
    pc->play_or_pause();  // start playing
    pc->pc->playback_seek(/*cfg_time*/90);      // seek at 90s    
}


but it doesnt work, the problem is brobably there

Code: [Select]
pc->play_or_pause();
pc->pc->playback_seek(/*cfg_time*/90);


is this fb2k behave correct, or do i something wrong ??
therefore i used timer, it seems that the solution works, but its not very clear

Code: [Select]
VOID CALLBACK seek_proc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
    static_api_ptr_t<playback_control> pc;
    pc->playback_seek(cfg_time);
    KillTimer(NULL, g_seek_timer_id);
}

class initquit_foobarstarter : public initquit
{
    void on_init();
    void on_quit();
};    

void initquit_foobarstarter::on_init()
{
    static_api_ptr_t<playback_control> pc;
    pc->play_or_pause();
    g_seek_timer_id = SetTimer(NULL, NULL, 200, seek_proc);
}

its possible do this without using timer ????

playback_control problem

Reply #1
I'm trying to write some general purpose plugin, i only need start playing the current song and seek at specified position after fb2k start. So i tryed this code

Code: [Select]
class initquit_foobarstarter : public initquit
{
    void on_init();
    void on_quit();
};    

void initquit_foobarstarter::on_init()
{
    static_api_ptr_t<playback_control> pc;    
    pc->play_or_pause();  // start playing
    pc->pc->playback_seek(/*cfg_time*/90);      // seek at 90s    
}


I'm not sure but it may be too soon to start playback

You may want to try:

Code: [Select]
class main_thread_play_callback : public main_thread_callback {

public:
    void callback_run() {
             static_api_ptr_t<playback_control> pc;    
             pc->play_or_pause();  // start playing
             pc->pc->playback_seek(/*cfg_time*/90);      // seek at 90s    
        }
};


and replace your code in on_init() by:

Code: [Select]
service_ptr_t<main_thread_play_callback> cb = new  service_impl_t<main_thread_play_callback>();
static_api_ptr_t<main_thread_callback_manager> cb_manager;
cb_manager->add_callback(cb);


This will ensure the task will run when all other plugins have been initialized

playback_control problem

Reply #2
The safest way is to use a main_thread_callback as bubbleguuum said. If I understand correctly, you want to start the current song at a specific position. The best way to do this is this (put this in callback_run()):
Code: [Select]
static_api_ptr_t<playback_control> pc;

// position from song start (you don't need this local variable, it's just for clarity)
double pos = 90.0;

// start playback in paused mode
pc->start(playback_control::track_command_play, true);

// seek to desired position
pc->seek(pos);

// unpause playback
pc->pause(false);

playback_control problem

Reply #3
thanks for replay, i will try

playback_control problem

Reply #4
so i used main_thread_callback as you both said, my callback_run() code is

Code: [Select]
void main_thread_callback_play::callback_run()
{
    static_api_ptr_t<playback_control> pc;    
    pc->start(playback_control::track_command_play, true);  // start playback in paused mode
    pc->playback_seek(cfg_time);
    pc->pause(false);  // unpause playback

    // create report message
    ostringstream ostr("callback_run\n");
    ostr << "can_seek: " << pc->playback_can_seek() << "\n";
    ostr << "desired seek position: " << cfg_time << "\n";
    ostr << "track position after seek: " << pc->playback_get_position() << "\n";

    popup_message::g_show(ostr.str().c_str(), "info");    
}


and report message created in callback_run() is:

can_seek: 0
desired seek position: 128
track position after seek: 0

so the problem is that fb2k is not ready to seek after playback_control::start(track_command_play)/playback_control::play_or_pause()  is executed and playback_control::playback_seek(pos) is ignored

any ideas ????

 
SimplePortal 1.0.0 RC1 © 2008-2020