use DBI;
use Getopt::Long;
use IO::Async::Signal;
+use IO::Async::Timer::Periodic;
use Log::Any qw($log);
use Net::Async::MPD;
use Object::Pad;
has $db :reader;
has $db_needs_update :writer = 1;
has $mpd :reader;
+ has $idler;
use constant DEFAULT_CONFIG_FILE => '/etc/mpd-feeder/mpd-feeder.conf';
method prepare_to_wait_idle {
$log->trace('declaring idle mode');
- $mpd->send('idle database playlist')->on_done(
+ $idler = $mpd->send('idle database playlist')->on_done(
sub {
my $result = shift;
$self->connect_mpd;
$self->connect_db;
+ $mpd->loop->add(
+ IO::Async::Timer::Periodic->new(
+ interval => 300,
+ on_tick => sub {
+ if ($idler) {
+ $log->trace('breaking idle to see if MPD is there');
+ undef $idler;
+ $log->trace("> noidle (direct)");
+ $mpd->{mpd_handle}->write("noidle\n");
+ }
+ },
+ )->start
+ );
+
for ( ;; ) {
$self->queue_songs( undef, sub { $self->prepare_to_wait_idle } );