… | |
… | |
7 | use AnyEvent::MPV; |
7 | use AnyEvent::MPV; |
8 | |
8 | |
9 | my $videofile = "path/to/file.mkv"; |
9 | my $videofile = "path/to/file.mkv"; |
10 | use AnyEvent; |
10 | use AnyEvent; |
11 | my $mpv = AnyEvent::MPV->new (trace => 1); |
11 | my $mpv = AnyEvent::MPV->new (trace => 1); |
12 | $mpv->start; |
12 | $mpv->start ("--idle=yes"); |
13 | $mpv->cmd (loadfile => $mpv->escape_binary ($videofile)); |
13 | $mpv->cmd (loadfile => $mpv->escape_binary ($videofile)); |
14 | my $quit = AE::cv; |
14 | my $quit = AE::cv; |
15 | $mpv->register_event (end_file => $cv); |
15 | $mpv->register_event (end_file => $quit); |
16 | $quit->recv; |
16 | $quit->recv; |
|
|
17 | |
17 | |
18 | |
18 | =head1 DESCRIPTION |
19 | =head1 DESCRIPTION |
19 | |
20 | |
20 | This module allows you to remote control F<mpv> (a video player). It also |
21 | This module allows you to remote control F<mpv> (a video player). It also |
21 | is an L<AnyEvent> user, you need to make sure that you use and run a |
22 | is an L<AnyEvent> user, you need to make sure that you use and run a |
… | |
… | |
220 | use Scalar::Util (); |
221 | use Scalar::Util (); |
221 | |
222 | |
222 | use AnyEvent (); |
223 | use AnyEvent (); |
223 | use AnyEvent::Util (); |
224 | use AnyEvent::Util (); |
224 | |
225 | |
225 | our $VERSION = '0.2'; |
226 | our $VERSION = '1.03'; |
226 | |
227 | |
227 | sub OBSID() { 0x10000000000000 } # 2**52 |
228 | sub OBSID() { 2**52 } |
228 | |
229 | |
229 | our $JSON = eval { require JSON::XS; JSON::XS:: } |
230 | our $JSON = eval { require JSON::XS; JSON::XS:: } |
230 | || do { require JSON::PP; JSON::PP:: }; |
231 | || do { require JSON::PP; JSON::PP:: }; |
231 | |
232 | |
232 | our $JSON_ENCODER = $JSON->new->utf8; |
233 | our $JSON_ENCODER = $JSON->new->utf8; |
… | |
… | |
395 | exit 1; |
396 | exit 1; |
396 | } |
397 | } |
397 | |
398 | |
398 | $self->{fh} = $fh; |
399 | $self->{fh} = $fh; |
399 | |
400 | |
400 | my $trace = delete $self->{trace} || sub { }; |
401 | my $trace = $self->{trace} || sub { }; |
401 | |
402 | |
402 | $trace = sub { warn "$_[0] $_[1]\n" } if $trace && !ref $trace; |
403 | $trace = sub { warn "$_[0] $_[1]\n" } if $trace && !ref $trace; |
403 | |
404 | |
404 | my $buf; |
405 | my $buf; |
405 | |
406 | |
… | |
… | |
487 | |
488 | |
488 | $trace->(">mpv" => $cmd); |
489 | $trace->(">mpv" => $cmd); |
489 | |
490 | |
490 | $wbuf .= "$cmd\n"; |
491 | $wbuf .= "$cmd\n"; |
491 | |
492 | |
492 | $self->{ww} ||= AE::io $fh, 1, sub { |
493 | my $wcb = sub { |
493 | my $len = syswrite $fh, $wbuf; |
494 | my $len = syswrite $fh, $wbuf; |
494 | substr $wbuf, 0, $len, ""; |
495 | substr $wbuf, 0, $len, ""; |
495 | undef $self->{ww} unless length $wbuf; |
496 | undef $self->{ww} unless length $wbuf; |
496 | }; |
497 | }; |
|
|
498 | |
|
|
499 | $wcb->(); |
|
|
500 | $self->{ww} ||= AE::io $fh, 1, $wcb if length $wbuf; |
497 | |
501 | |
498 | $cv |
502 | $cv |
499 | }; |
503 | }; |
500 | |
504 | |
501 | 1 |
505 | 1 |
… | |
… | |
566 | For subclassing, see I<SUBCLASSING>, below. |
570 | For subclassing, see I<SUBCLASSING>, below. |
567 | |
571 | |
568 | =cut |
572 | =cut |
569 | |
573 | |
570 | sub on_event { |
574 | sub on_event { |
571 | my ($self, $key) = @_; |
575 | my ($self, $event, $data) = @_; |
572 | |
576 | |
573 | $self->{on_event}($self, $key) if $self->{on_event}; |
577 | $self->{on_event}($self, $event, $data) if $self->{on_event}; |
574 | } |
578 | } |
575 | |
579 | |
576 | =item $mpv->on_key ($string) |
580 | =item $mpv->on_key ($string) |
577 | |
581 | |
578 | Invoked when a key declared by C<< ->bind_key >> is pressed. The default |
582 | Invoked when a key declared by C<< ->bind_key >> is pressed. The default |