App-MediaPi
view release on metacpan or search on metacpan
script/mediapi view on Meta::CPAN
$track_nb = $1;
print "track_nb: '${track_nb}'\n";
} else {
undef $track_nb;
}
if ($info =~ m/track_total: (\d+)/) {
$track_total = $1;
print "track_total: '${track_total}'\n";
} else {
undef $track_total;
}
}
sub read_track_length {
my ($data) = @_;
if ($data =~ m/(\d+)/) {
$track_length = $1;
} else {
undef $track_length;
}
print "track_length: '${track_length}'\n";
}
sub read_track_time {
my ($data) = @_;
if ($data =~ m/(\d+)/) {
$track_time = $1;
} else {
undef $track_time;
}
print "track_time: '${track_time}'\n";
# This is not necessarily the last of our callback, but if it isnât itâs not
# a big deal.
refresh_status_data();
}
sub refresh_status_data {
if (!$is_playing) {
$track_status = 'not playing';
} else {
$track_status = sprintf 'track %s/%s, time %s / %s',
($track_nb // '??'), ($track_total // '??'),
(defined $track_time ? sprintf('%d:%02d', $track_time / 60, $track_time % 60) : '??'),
(defined $track_length ? sprintf('%d:%02d', $track_length / 60, $track_length % 60) : '??'),
}
Tkx::after(200, \&get_status);
}
my $play_btn = $media_control_frame->new_ttk__button(-text => 'âµ', -style => 'Unicode.TButton', -command => sub { send_cmd('add cdda:///dev/cdrom') });
$play_btn->g_grid(-column => 0, -row => 0, -sticky => 'nswe', -padx => 10, -pady => 10);
my $pause_btn = $media_control_frame->new_ttk__button(-text => 'â¸', -style => 'Unicode.TButton',
-command => sub { send_cmd('pause') });
$pause_btn->g_grid(-column => 1, -row => 0, -sticky => 'nswe', -padx => 10, -pady => 10);
my $prev_btn = $media_control_frame->new_ttk__button(-text => 'â®', -style => 'Unicode.TButton',
-command => sub { send_cmd('prev') });
$prev_btn->g_grid(-column => 0, -row => 1, -sticky => 'nswe', -padx => 10, -pady => 10);
my $next_btn = $media_control_frame->new_ttk__button(-text => 'â', -style => 'Unicode.TButton',
-command => sub { send_cmd('next') });
$next_btn->g_grid(-column => 1, -row => 1, -sticky => 'nswe', -padx => 10, -pady => 10);
my $status_label = $media_control_frame->new_ttk__label(-textvariable => \$track_status, -anchor => 'center');
$status_label->g_grid(-column => 0, -columnspan => 2, -row => 2, -sticky => 'nswe');
# This remove the focus and "active" decoration of the button when they are selected.
# We might want some kind of feedback that they were selected though.
Tkx::bind('TButton', '<FocusIn>', [sub { $wnd->g_focus(); Tkx::widget->new($_[0])->state('!active'); }, Tkx::Ev('%W')]);
# The commands are documented at https://abyz.me.uk/rpi/pigpio/pigs.html
# For now we donât have a gpio for that as 18 is used by the I2S audio, we need
# to route another one to that pin on the screen.
# syswrite $pigpio, "w 18 1\n"; # Switch on the backlight of the screen.
#Tkx::bind('.', '<Create>', sub {
Tkx::after('idle', sub {
send_cmd(); # Used to read the greeting message until the first caret >.
get_status();
});
print "Starting main loop\n";
Tkx::MainLoop();
( run in 3.076 seconds using v1.01-cache-2.11-cpan-2398b32b56e )