App-DrivePlayer
view release on metacpan or search on metacpan
lib/App/DrivePlayer/GUI.pm view on Meta::CPAN
exec('pkexec', 'apt-get', 'install', '-y', 'libchromaprint-tools')
or POSIX::_exit(1);
}
# Poll every 500 ms until the child exits
Glib::Timeout->add(500, sub {
my $res = waitpid($pid, WNOHANG());
if ($res == $pid) {
$refresh_fp_status->();
$install_btn->set_sensitive(TRUE);
return FALSE; # remove timer
}
return TRUE; # keep polling
});
});
# AcoustID API key
my $aid_lbl = Gtk3::Label->new('AcoustID API Key:');
$aid_lbl->set_xalign(1.0);
$fp_grid->attach($aid_lbl, 0, 1, 1, 1);
lib/App/DrivePlayer/Player.pm view on Meta::CPAN
sub get_volume {
my ($self) = @_;
my $resp = $self->_send_command_sync(['get_property', 'volume']);
return $resp ? $resp->{data} : 50;
}
sub state { $_[0]->_state }
sub current_track { $_[0]->_current_track }
# Called by GUI timer to poll position / detect track end
sub poll {
my ($self) = @_;
return if $self->_state eq 'stop';
return unless $self->_socket;
$self->_drain_events();
my $pos_resp = $self->_send_command_sync(['get_property', 'time-pos']);
my $dur_resp = $self->_send_command_sync(['get_property', 'duration']);
lib/App/DrivePlayer/Player.pm view on Meta::CPAN
on_position => sub { my ($pos_s, $dur_s) = @_; ... },
);
$player->play({ drive_id => $file_id, title => 'Song' });
$player->pause_resume;
$player->seek(90); # jump to 1:30
$player->set_volume(80); # 0-100
$player->stop;
$player->quit; # terminate mpv
# Call periodically from a GUI timer:
$player->poll;
=head1 DESCRIPTION
Controls an C<mpv> subprocess via its JSON IPC socket. Audio files are
streamed directly from Google Drive using the Drive media URL with a Bearer
token injected as an HTTP header. The Bearer token is cached and
automatically refreshed after 55 minutes.
mpv is started lazily on the first call to L</play> and reused for
lib/App/DrivePlayer/Player.pm view on Meta::CPAN
my $track = $player->current_track; # hashref or undef
Return the track hashref passed to the most recent L</play> call.
=head2 poll
$player->poll;
Query mpv for the current playback position and duration, firing the
C<on_position> callback if both are available. Also drains any pending
mpv events. Intended to be called from a periodic GUI timer.
=head2 quit
$player->quit;
Send a quit command to mpv, wait briefly, then SIGTERM it if still
running. Closes the IPC socket. Should be called when the application
exits.
=cut
( run in 0.737 second using v1.01-cache-2.11-cpan-bbcb1afb8fc )