ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MPV/MPV.pm
(Generate patch)

Comparing AnyEvent-MPV/MPV.pm (file contents):
Revision 1.15 by root, Wed Mar 22 01:00:36 2023 UTC vs.
Revision 1.20 by root, Sat Apr 1 06:32:32 2023 UTC

3AnyEvent::MPV - remote control mpv (https://mpv.io) 3AnyEvent::MPV - remote control mpv (https://mpv.io)
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use AnyEvent::MPV; 7 use AnyEvent::MPV;
8
9 my $videofile = "path/to/file.mkv";
10 use AnyEvent;
11 my $mpv = AnyEvent::MPV->new (trace => 1);
12 $mpv->start ("--idle=yes");
13 $mpv->cmd (loadfile => $mpv->escape_binary ($videofile));
14 my $quit = AE::cv;
15 $mpv->register_event (end_file => $quit);
16 $quit->recv;
17
8 18
9=head1 DESCRIPTION 19=head1 DESCRIPTION
10 20
11This module allows you to remote control F<mpv> (a video player). It also 21This module allows you to remote control F<mpv> (a video player). It also
12is an L<AnyEvent> user, you need to make sure that you use and run a 22is an L<AnyEvent> user, you need to make sure that you use and run a
50Here is a very simple client: 60Here is a very simple client:
51 61
52 use AnyEvent; 62 use AnyEvent;
53 use AnyEvent::MPV; 63 use AnyEvent::MPV;
54 64
55 my $videofile = "./xyzzy.mp4"; 65 my $videofile = "./xyzzy.mkv";
56 66
57 my $mpv = AnyEvent::MPV->new (trace => 1); 67 my $mpv = AnyEvent::MPV->new (trace => 1);
58 68
59 $mpv->start ("--", $videofile); 69 $mpv->start ("--", $videofile);
60 70
85shell command), so let us load the file at runtime: 95shell command), so let us load the file at runtime:
86 96
87 use AnyEvent; 97 use AnyEvent;
88 use AnyEvent::MPV; 98 use AnyEvent::MPV;
89 99
90 my $videofile = "./xyzzy.mp4"; 100 my $videofile = "./xyzzy.mkv";
91 101
92 my $mpv = AnyEvent::MPV->new ( 102 my $mpv = AnyEvent::MPV->new (
93 trace => 1, 103 trace => 1,
94 args => ["--pause", "--idle=yes"], 104 args => ["--pause", "--idle=yes"],
95 ); 105 );
140receiving events (using a somewhat embellished example): 150receiving events (using a somewhat embellished example):
141 151
142 use AnyEvent; 152 use AnyEvent;
143 use AnyEvent::MPV; 153 use AnyEvent::MPV;
144 154
145 my $videofile = "xyzzy.mp4"; 155 my $videofile = "xyzzy.mkv";
146 156
147 my $quit = AE::cv; 157 my $quit = AE::cv;
148 158
149 my $mpv = AnyEvent::MPV->new ( 159 my $mpv = AnyEvent::MPV->new (
150 trace => 1, 160 trace => 1,
211use Scalar::Util (); 221use Scalar::Util ();
212 222
213use AnyEvent (); 223use AnyEvent ();
214use AnyEvent::Util (); 224use AnyEvent::Util ();
215 225
216our $VERSION = '0.2'; 226our $VERSION = '1.03';
217 227
218sub OBSID() { 0x10000000000000 } # 2**52 228sub OBSID() { 2**52 }
219 229
220our $JSON = eval { require JSON::XS; JSON::XS:: } 230our $JSON = eval { require JSON::XS; JSON::XS:: }
221 || do { require JSON::PP; JSON::PP:: }; 231 || do { require JSON::PP; JSON::PP:: };
222 232
223our $JSON_ENCODER = $JSON->new->utf8; 233our $JSON_ENCODER = $JSON->new->utf8;
386 exit 1; 396 exit 1;
387 } 397 }
388 398
389 $self->{fh} = $fh; 399 $self->{fh} = $fh;
390 400
391 my $trace = delete $self->{trace} || sub { }; 401 my $trace = $self->{trace} || sub { };
392 402
393 $trace = sub { warn "$_[0] $_[1]\n" } if $trace && !ref $trace; 403 $trace = sub { warn "$_[0] $_[1]\n" } if $trace && !ref $trace;
394 404
395 my $buf; 405 my $buf;
396 406
478 488
479 $trace->(">mpv" => $cmd); 489 $trace->(">mpv" => $cmd);
480 490
481 $wbuf .= "$cmd\n"; 491 $wbuf .= "$cmd\n";
482 492
483 $self->{ww} ||= AE::io $fh, 1, sub { 493 my $wcb = sub {
484 my $len = syswrite $fh, $wbuf; 494 my $len = syswrite $fh, $wbuf;
485 substr $wbuf, 0, $len, ""; 495 substr $wbuf, 0, $len, "";
486 undef $self->{ww} unless length $wbuf; 496 undef $self->{ww} unless length $wbuf;
487 }; 497 };
498
499 $wcb->();
500 $self->{ww} ||= AE::io $fh, 1, $wcb if length $wbuf;
488 501
489 $cv 502 $cv
490 }; 503 };
491 504
492 1 505 1
557For subclassing, see I<SUBCLASSING>, below. 570For subclassing, see I<SUBCLASSING>, below.
558 571
559=cut 572=cut
560 573
561sub on_event { 574sub on_event {
562 my ($self, $key) = @_; 575 my ($self, $event, $data) = @_;
563 576
564 $self->{on_event}($self, $key) if $self->{on_event}; 577 $self->{on_event}($self, $event, $data) if $self->{on_event};
565} 578}
566 579
567=item $mpv->on_key ($string) 580=item $mpv->on_key ($string)
568 581
569Invoked when a key declared by C<< ->bind_key >> is pressed. The default 582Invoked when a key declared by C<< ->bind_key >> is pressed. The default
822care and deal with the breakage. 835care and deal with the breakage.
823 836
824If you don't want to go to the effort of subclassing this module, you can 837If you don't want to go to the effort of subclassing this module, you can
825also specify all event handlers as constructor keys. 838also specify all event handlers as constructor keys.
826 839
840=head1 EXAMPLES
841
842Here are some real-world code snippets, thrown in here mainly to give you
843some example code to copy.
844
845=head2 doomfrontend
846
847At one point I replaced mythtv-frontend by my own terminal-based video
848player (based on rxvt-unicode). I toyed with the diea of using F<mpv>'s
849subtitle engine to create the user interface, but that is hard to use
850since you don't know how big your letters are. It is also where most of
851this modules code has originally been developed in.
852
853It uses a unified input queue to handle various remote controls, so its
854event handling needs are very simple - it simply feeds all events into the
855input queue:
856
857 my $mpv = AnyEvent::MPV->new (
858 mpv => $MPV,
859 args => \@MPV_ARGS,
860 on_event => sub {
861 input_feed "mpv/$_[1]", $_[2];
862 },
863 on_key => sub {
864 input_feed $_[1];
865 },
866 on_eof => sub {
867 input_feed "mpv/quit";
868 },
869 );
870
871 ...
872
873 $mpv->start ("--idle=yes", "--pause", "--force-window=no");
874
875It also doesn't use complicated command line arguments - the file search
876options have the most impact, as they prevent F<mpv> from scanning
877directories with tens of thousands of files for subtitles and more:
878
879 --audio-client-name=doomfrontend
880 --osd-on-seek=msg-bar --osd-bar-align-y=-0.85 --osd-bar-w=95
881 --sub-auto=exact --audio-file-auto=exact
882
883Since it runs on a TV without a desktop environemnt, it tries to keep complications such as dbus
884away and the screensaver happy:
885
886 # prevent xscreensaver from doing something stupid, such as starting dbus
887 $ENV{DBUS_SESSION_BUS_ADDRESS} = "/"; # prevent dbus autostart for sure
888 $ENV{XDG_CURRENT_DESKTOP} = "generic";
889
890It does bind a number of keys to internal (to doomfrontend) commands:
891
892 for (
893 List::Util::pairs qw(
894 ESC return
895 q return
896 ENTER enter
897 SPACE pause
898 [ steprev
899 ] stepfwd
900 j subtitle
901 BS red
902 i green
903 o yellow
904 b blue
905 D triangle
906 UP up
907 DOWN down
908 RIGHT right
909 LEFT left
910 ),
911 (map { ("KP$_" => "num$_") } 0..9),
912 KP_INS => 0, # KP0, but different
913 ) {
914 $mpv->bind_key ($_->[0] => $_->[1]);
915 }
916
917It also reacts to sponsorblock chapters, so it needs to know when vidoe
918chapters change. Preadting C<AnyEvent::MPV>, it handles observers
919manually:
920
921 $mpv->cmd (observe_property => 1, "chapter-metadata");
922
923It also tries to apply an F<mpv> profile, if it exists:
924
925 eval {
926 # the profile is optional
927 $mpv->cmd ("apply-profile" => "doomfrontend");
928 };
929
930Most of the complicated parts deal with saving and restoring per-video
931data, such as bookmarks, playing position, selected audio and subtitle
932tracks and so on. However, since it uses L<Coro>, it can conveniently
933block and wait for replies, which is n ot possible in purely event based
934programs, as you are not allowed to block inside event callbacks in most
935event loops. This simplifies the code quite a bit.
936
937When the file to be played is a Tv recording done by mythtv, it uses the
938C<appending> protocol and deinterlacing:
939
940 if (is_myth $mpv_path) {
941 $mpv_path = "appending://$mpv_path";
942 $initial_deinterlace = 1;
943 }
944
945Otherwise, it sets some defaults and loads the file (I forgot what the
946C<dummy> argument is for, but I am sure it is needed by some F<mpv>
947version):
948
949 $mpv->cmd ("script-message", "osc-visibility", "never", "dummy");
950 $mpv->cmd ("set", "vid", "auto");
951 $mpv->cmd ("set", "aid", "auto");
952 $mpv->cmd ("set", "sid", "no");
953 $mpv->cmd ("set", "file-local-options/chapters-file", $mpv->escape_binary ("$mpv_path.chapters"));
954 $mpv->cmd ("loadfile", $mpv->escape_binary ($mpv_path));
955 $mpv->cmd ("script-message", "osc-visibility", "auto", "dummy");
956
957Handling events makes the main bulk of video playback code. For example,
958various ways of ending playback:
959
960 if ($INPUT eq "mpv/quit") { # should not happen, but allows user to kill etc. without consequence
961 $status = 1;
962 mpv_init; # try reinit
963 last;
964
965 } elsif ($INPUT eq "mpv/idle") { # normal end-of-file
966 last;
967
968 } elsif ($INPUT eq "return") {
969 $status = 1;
970 last;
971
972Or the code that actually starts playback, once the file is loaded:
973
974 our %SAVE_PROPERTY = (aid => 1, sid => 1, "audio-delay" => 1);
975
976 ...
977
978 my $oid = 100;
979
980 } elsif ($INPUT eq "mpv/file-loaded") { # start playing, configure video
981 $mpv->cmd ("seek", $playback_start, "absolute+exact") if $playback_start > 0;
982
983 my $target_fps = eval { $mpv->cmd_recv ("get_property", "container-fps") } || 60;
984 $target_fps *= play_video_speed_mult;
985 set_fps $target_fps;
986
987 unless (eval { $mpv->cmd_recv ("get_property", "video-format") }) {
988 $mpv->cmd ("set", "file-local-options/lavfi-complex", "[aid1] asplit [ao], showcqt=..., format=yuv420p [vo]");
989 };
990
991 for my $prop (keys %SAVE_PROPERTY) {
992 if (exists $PLAYING_STATE->{"mpv_$prop"}) {
993 $mpv->cmd ("set", "$prop", $PLAYING_STATE->{"mpv_$prop"} . "");
994 }
995
996 $mpv->cmd ("observe_property", ++$oid, $prop);
997 }
998
999 play_video_set_speed;
1000 $mpv->cmd ("set", "osd-level", "$OSD_LEVEL");
1001 $mpv->cmd ("observe_property", ++$oid, "osd-level");
1002 $mpv->cmd ("set", "pause", "no");
1003
1004 $mpv->cmd ("set_property", "deinterlace", "yes")
1005 if $initial_deinterlace;
1006
1007There is a lot going on here. First it seeks to the actual playback
1008position, if it is not at the start of the file (it would probaby be more
1009efficient to set the starting position before loading the file, though,
1010but this is good enough).
1011
1012Then it plays with the display fps, to set it to something harmonious
1013w.r.t. the video framerate.
1014
1015If the file does not have a video part, it assumes it is an audio file and
1016sets a visualizer.
1017
1018Also, a number of properties are not global, but per-file. At the moment,
1019this is C<audio-delay>, and the current audio/subtitle track, which it
1020sets, and also creates an observer. Again, this doesn'T use the observe
1021functionality of this module, but handles it itself, assigning obsevrer
1022ids 100+ to temporary/per-file observers.
1023
1024Lastly, it sets some global (or per-youtube-uploader) parameters, such as
1025speed, and unpauses. Property changes are handled like other input events:
1026
1027 } elsif ($INPUT eq "mpv/property-change") {
1028 my $prop = $INPUT_DATA->{name};
1029
1030 if ($prop eq "chapter-metadata") {
1031 if ($INPUT_DATA->{data}{TITLE} =~ /^\[SponsorBlock\]: (.*)/) {
1032 my $section = $1;
1033 my $skip;
1034
1035 $skip ||= $SPONSOR_SKIP{$_}
1036 for split /\s*,\s*/, $section;
1037
1038 if (defined $skip) {
1039 if ($skip) {
1040 # delay a bit, in case we get two metadata changes in quick succession, e.g.
1041 # because we have a skip at file load time.
1042 $skip_delay = AE::timer 2/50, 0, sub {
1043 $mpv->cmd ("no-osd", "add", "chapter", 1);
1044 $mpv->cmd ("show-text", "skipped sponsorblock section \"$section\"", 3000);
1045 };
1046 } else {
1047 undef $skip_delay;
1048 $mpv->cmd ("show-text", "NOT skipping sponsorblock section \"$section\"", 3000);
1049 }
1050 } else {
1051 $mpv->cmd ("show-text", "UNRECOGNIZED sponsorblock section \"$section\"", 60000);
1052 }
1053 } else {
1054 # cancel a queued skip
1055 undef $skip_delay;
1056 }
1057
1058 } elsif (exists $SAVE_PROPERTY{$prop}) {
1059 $PLAYING_STATE->{"mpv_$prop"} = $INPUT_DATA->{data};
1060 ::state_save;
1061 }
1062
1063This saves back the per-file properties, and also handles chapter changes
1064in a hacky way.
1065
1066Most of the handlers are very simple, though. For example:
1067
1068 } elsif ($INPUT eq "pause") {
1069 $mpv->cmd ("cycle", "pause");
1070 $PLAYING_STATE->{curpos} = $mpv->cmd_recv ("get_property", "playback-time");
1071 } elsif ($INPUT eq "right") {
1072 $mpv->cmd ("osd-msg-bar", "seek", 30, "relative+exact");
1073 } elsif ($INPUT eq "left") {
1074 $mpv->cmd ("osd-msg-bar", "seek", -5, "relative+exact");
1075 } elsif ($INPUT eq "up") {
1076 $mpv->cmd ("osd-msg-bar", "seek", +600, "relative+exact");
1077 } elsif ($INPUT eq "down") {
1078 $mpv->cmd ("osd-msg-bar", "seek", -600, "relative+exact");
1079 } elsif ($INPUT eq "select") {
1080 $mpv->cmd ("osd-msg-bar", "add", "audio-delay", "-0.100");
1081 } elsif ($INPUT eq "start") {
1082 $mpv->cmd ("osd-msg-bar", "add", "audio-delay", "0.100");
1083 } elsif ($INPUT eq "intfwd") {
1084 $mpv->cmd ("no-osd", "frame-step");
1085 } elsif ($INPUT eq "audio") {
1086 $mpv->cmd ("osd-auto", "cycle", "audio");
1087 } elsif ($INPUT eq "subtitle") {
1088 $mpv->cmd ("osd-auto", "cycle", "sub");
1089 } elsif ($INPUT eq "triangle") {
1090 $mpv->cmd ("osd-auto", "cycle", "deinterlace");
1091
1092Once a file has finished playing (or the user strops playback), it pauses,
1093unobserves the per-file observers, and saves the current position for to
1094be able to resume:
1095
1096 $mpv->cmd ("set", "pause", "yes");
1097
1098 while ($oid > 100) {
1099 $mpv->cmd ("unobserve_property", $oid--);
1100 }
1101
1102 $PLAYING_STATE->{curpos} = $mpv->cmd_recv ("get_property", "playback-time");
1103
1104And thats most of the F<mpv>-related code.
1105
1106=head2 F<Gtk2::CV>
1107
1108F<Gtk2::CV> is low-feature image viewer that I use many times daily
1109because it can handle directories with millions of files without falling
1110over. It also had the ability to play videos for ages, but it used an
1111older, crappier protocol to talk to F<mpv> and used F<ffprobe> before
1112playing each file instead of letting F<mpv> handle format/size detection.
1113
1114After writing this module, I decided to upgprade Gtk2::CV by making use
1115of it, with the goal of getting rid of F<ffprobe> and being ablew to
1116reuse F<mpv> processes, which would have a multitude of speed benefits
1117(for example, fork+exec of F<mpv> caused the kernel to close all file
1118descriptors, which could take minutes if a large file was being copied via
1119NFS, as the kernel waited for thr buffers to be flushed on close - not
1120having to start F<mpv> gets rid of this issue).
1121
1122Setting up is only complicated by the fact that F<mpv> needs to be
1123embedded into an existing window. To keep control of all inputs,
1124F<Gtk2::CV> puts an eventbox in front of F<mpv>, so F<mpv> receives no
1125input events:
1126
1127 $self->{mpv} = AnyEvent::MPV->new (
1128 trace => $ENV{CV_MPV_TRACE},
1129 );
1130
1131 # create an eventbox, so we receive all input events
1132 my $box = $self->{mpv_eventbox} = new Gtk2::EventBox;
1133 $box->set_above_child (1);
1134 $box->set_visible_window (0);
1135 $box->set_events ([]);
1136 $box->can_focus (0);
1137
1138 # create a drawingarea that mpv can display into
1139 my $window = $self->{mpv_window} = new Gtk2::DrawingArea;
1140 $box->add ($window);
1141
1142 # put the drawingarea intot he eventbox, and the eventbox into our display window
1143 $self->add ($box);
1144
1145 # we need to pass the window id to F<mpv>, which means we need to realise
1146 # the drawingarea, so an X window is allocated for it.
1147 $self->show_all;
1148 $window->realize;
1149 my $xid = $window->window->get_xid;
1150
1151Then it starts F<mpv> using this setup:
1152
1153 local $ENV{LC_ALL} = "POSIX";
1154 $self->{mpv}->start (
1155 "--no-terminal",
1156 "--no-input-terminal",
1157 "--no-input-default-bindings",
1158 "--no-input-cursor",
1159 "--input-conf=/dev/null",
1160 "--input-vo-keyboard=no",
1161
1162 "--loop-file=inf",
1163 "--force-window=yes",
1164 "--idle=yes",
1165
1166 "--audio-client-name=CV",
1167
1168 "--osc=yes", # --osc=no displays fading play/pause buttons instead
1169
1170 "--wid=$xid",
1171 );
1172
1173 $self->{mpv}->cmd ("script-message" => "osc-visibility" => "never", "dummy");
1174 $self->{mpv}->cmd ("osc-idlescreen" => "no");
1175
1176It also prepares a hack to force a ConfigureNotify event on every vidoe
1177reconfig:
1178
1179 # force a configurenotify on every video-reconfig
1180 $self->{mpv_reconfig} = $self->{mpv}->register_event (video_reconfig => sub {
1181 my ($mpv, $event, $data) = @_;
1182
1183 $self->mpv_window_update;
1184 });
1185
1186The way this is done is by doing a "dummy" resize to 1x1 and back:
1187
1188 $self->{mpv_window}->window->resize (1, 1),
1189 $self->{mpv_window}->window->resize ($self->{w}, $self->{h});
1190
1191Without this, F<mpv> often doesn't "get" the correct window size. Doing
1192it this way is not nice, but I didn't fine a nicer way to do it.
1193
1194When no file is being played, F<mpv> is hidden and prepared:
1195
1196 $self->{mpv_eventbox}->hide;
1197
1198 $self->{mpv}->cmd (set_property => "pause" => "yes");
1199 $self->{mpv}->cmd ("playlist_remove", "current");
1200 $self->{mpv}->cmd (set_property => "video-rotate" => 0);
1201 $self->{mpv}->cmd (set_property => "lavfi-complex" => "");
1202
1203Loading a file is a bit more complicated, as bluray and DVD rips are
1204supported:
1205
1206 if ($moviedir) {
1207 if ($moviedir eq "br") {
1208 $mpv->cmd (set => "bluray-device" => $path);
1209 $mpv->cmd (loadfile => "bd://");
1210 } elsif ($moviedir eq "dvd") {
1211 $mpv->cmd (set => "dvd-device" => $path);
1212 $mpv->cmd (loadfile => "dvd://");
1213 }
1214 } elsif ($type eq "video/iso-bluray") {
1215 $mpv->cmd (set => "bluray-device" => $path);
1216 $mpv->cmd (loadfile => "bd://");
1217 } else {
1218 $mpv->cmd (loadfile => $mpv->escape_binary ($path));
1219 }
1220
1221After this, C<Gtk2::CV> waits for the file to be loaded, video to be
1222configured, and then queries the video size (to resize its own window)
1223and video format (to decide whether an audio visualizer is needed for
1224audio playback). The problematic word here is "wait", as this needs to be
1225imploemented using callbacks.
1226
1227This made the code much harder to write, as the whole setup is very
1228asynchronous (C<Gtk2::CV> talks to the command interface in F<mpv>, which
1229talks to the decode and playback parts, all of which run asynchronously
1230w.r.t. each other. In practise, this can mean that C<Gtk2::CV> waits for
1231a file to be loaded by F<mpv> while the command interface of F<mpv> still
1232deals with the previous file and the decoder still handles an even older
1233file). Adding to this fact is that Gtk2::CV is bound by the glib event
1234loop, which means we cannot wait for replies form F<mpv> anywhere, so
1235everything has to be chained callbacks.
1236
1237The way this is handled is by creating a new empty hash ref that is unique
1238for each loaded file, and use it to detect whether the event is old or
1239not, and also store C<AnyEvent::MPV> guard objects in it:
1240
1241 # every time we loaded a file, we create a new hash
1242 my $guards = $self->{mpv_guards} = { };
1243
1244Then, when we wait for an event to occur, delete the handler, and, if the
1245C<mpv_guards> object has changed, we ignore it. Something like this:
1246
1247 $guards->{file_loaded} = $mpv->register_event (file_loaded => sub {
1248 delete $guards->{file_loaded};
1249 return if $guards != $self->{mpv_guards};
1250
1251Commands do not have guards since they cnanot be cancelled, so we don't
1252have to do this for commands. But what prevents us form misinterpreting
1253an old event? Since F<mpv> (by default) handles commands synchronously,
1254we can queue a dummy command, whose only purpose is to tell us when all
1255previous commands are done. We use C<get_version> for this.
1256
1257The simplified code looks like this:
1258
1259 Scalar::Util::weaken $self;
1260
1261 $mpv->cmd ("get_version")->cb (sub {
1262
1263 $guards->{file_loaded} = $mpv->register_event (file_loaded => sub {
1264 delete $guards->{file_loaded};
1265 return if $guards != $self->{mpv_guards};
1266
1267 $mpv->cmd (get_property => "video-format")->cb (sub {
1268 return if $guards != $self->{mpv_guards};
1269
1270 # video-format handling
1271 return if eval { $_[0]->recv; 1 };
1272
1273 # no video? assume audio and visualize, cpu usage be damned
1274 $mpv->cmd (set => "lavfi-complex" => ...");
1275 });
1276
1277 $guards->{show} = $mpv->register_event (video_reconfig => sub {
1278 delete $guards->{show};
1279 return if $guards != $self->{mpv_guards};
1280
1281 $self->{mpv_eventbox}->show_all;
1282
1283 $w = $mpv->cmd (get_property => "dwidth");
1284 $h = $mpv->cmd (get_property => "dheight");
1285
1286 $h->cb (sub {
1287 $w = eval { $w->recv };
1288 $h = eval { $h->recv };
1289
1290 $mpv->cmd (set_property => "pause" => "no");
1291
1292 if ($w && $h) {
1293 # resize our window
1294 }
1295
1296 });
1297 });
1298
1299 });
1300
1301 });
1302
1303Most of the rest of the code is much simpler and just deals with forwarding user commands:
1304
1305 } elsif ($key == $Gtk2::Gdk::Keysyms{Right}) { $mpv->cmd ("osd-msg-bar" => seek => "+10");
1306 } elsif ($key == $Gtk2::Gdk::Keysyms{Left} ) { $mpv->cmd ("osd-msg-bar" => seek => "-10");
1307 } elsif ($key == $Gtk2::Gdk::Keysyms{Up} ) { $mpv->cmd ("osd-msg-bar" => seek => "+60");
1308 } elsif ($key == $Gtk2::Gdk::Keysyms{Down} ) { $mpv->cmd ("osd-msg-bar" => seek => "-60");
1309 } elsif ($key == $Gtk2::Gdk::Keysyms{a}) ) { $mpv->cmd ("osd-msg-msg" => cycle => "audio");
1310 } elsif ($key == $Gtk2::Gdk::Keysyms{j} ) { $mpv->cmd ("osd-msg-msg" => cycle => "sub");
1311 } elsif ($key == $Gtk2::Gdk::Keysyms{o} ) { $mpv->cmd ("no-osd" => "cycle-values", "osd-level", "2", "3", "0", "2");
1312 } elsif ($key == $Gtk2::Gdk::Keysyms{p} ) { $mpv->cmd ("no-osd" => cycle => "pause");
1313 } elsif ($key == $Gtk2::Gdk::Keysyms{9} ) { $mpv->cmd ("osd-msg-bar" => add => "ao-volume", "-2");
1314 } elsif ($key == $Gtk2::Gdk::Keysyms{0} ) { $mpv->cmd ("osd-msg-bar" => add => "ao-volume", "+2");
1315
827=head1 SEE ALSO 1316=head1 SEE ALSO
828 1317
829L<AnyEvent>, L<the mpv command documentation|https://mpv.io/manual/stable/#command-interface>. 1318L<AnyEvent>, L<the mpv command documentation|https://mpv.io/manual/stable/#command-interface>.
830 1319
831=head1 AUTHOR 1320=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines