App-MediaPi
view release on metacpan or search on metacpan
script/mediapi view on Meta::CPAN
my $wnd = Tkx::widget->new('.');
# fullscreen removes the border of the window but does not actually make it
# fullscreen (maybe because we donât have a real window manager... which also
# means that we donât have a border anyway).
$wnd->g_wm_attribute(-fullscreen => 1, -topmost => 1);
$wnd->g_wm_resizable(0, 0);
$wnd->configure(-cursor => 'none');
$wnd->g_wm_geometry("${screen_x}x${screen_y}");
my $media_control_frame = $wnd->new_ttk__frame(-borderwidth => 5); # The border is here only to debug
$media_control_frame->g_grid(-column => 0, -row => 0, -sticky => 'nswe');
$wnd->g_grid_columnconfigure(0, -weight => 1);
$wnd->g_grid_rowconfigure(0, -weight => 1);
# The default font does not have the media control glyphs. So letâs create a
# style using Unifont that has almost all glyphs.
# Useful link: https://en.wikipedia.org/wiki/Media_control_symbols
Tkx::ttk__style_configure('Unicode.TButton', -font => 'Unifont 15');
$media_control_frame->g_grid_columnconfigure(0, -weight => 1);
$media_control_frame->g_grid_columnconfigure(1, -weight => 1);
$media_control_frame->g_grid_rowconfigure(0, -weight => 1);
$media_control_frame->g_grid_rowconfigure(1, -weight => 1);
my $vlc_in;
my $vlc_out;
# my $vlc = IPC::Run::start ['vlc', '--intf', 'rc', '--alsa-audio-device', 'dac'], $vlc_in;
my $vlc = IPC::Run::start ['vlc', '--intf', 'rc'], $vlc_in, \$vlc_out;
$vlc_in = '';
$vlc_out = '';
# Itâs unclear what is the default volume and what is the real max level that can
script/mediapi view on Meta::CPAN
$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.
( run in 1.383 second using v1.01-cache-2.11-cpan-e1769b4cff6 )