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
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
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
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 ????
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
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:
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:
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
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()):
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);
thanks for replay, i will try
so i used main_thread_callback as you both said, my callback_run() code is
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 ????