AnyEvent-MPV
view release on metacpan or search on metacpan
In the C<start-file> event, we again set the C<pause> property to C<no>
so the movie starts playing. For the C<end-file> event, we tell the main
program to quit by invoking C<$quit>.
This should conclude the basics of operation. There are a few more
examples later in the documentation.
=head2 ENCODING CONVENTIONS
As a rule of thumb, all data you pass to this module to be sent to F<mpv>
is expected to be in unicode. To pass something that isn't, you need to
escape it using C<escape_binary>.
Data received from F<mpv>, however, is I<not> decoded to unicode, as data
returned by F<mpv> is not generally encoded in unicode, and the encoding
is usually unspecified. So if you receive data and expect it to be in
unicode, you need to first decode it from UTF-8, but note that this might
fail. This is not a limitation of this module - F<mpv> simply does not
specify nor guarantee a specific encoding, or any encoding at all, in its
protocol.
=head2 METHODS
=over
=cut
bless {
mpv => "mpv",
args => [],
%kv,
}, $class
}
=item $string = $mpv->escape_binary ($string)
This module excects all command data sent to F<mpv> to be in unicode. Some
things are not, such as filenames. To pass binary data such as filenames
through a comamnd, you need to escape it using this method.
The simplest example is a C<loadfile> command:
$mpv->cmd_recv (loadfile => $mpv->escape_binary ($path));
=cut
# can be used to escape filenames
also specify all event handlers as constructor keys.
=head1 EXAMPLES
Here are some real-world code snippets, thrown in here mainly to give you
some example code to copy.
=head2 doomfrontend
At one point I replaced mythtv-frontend by my own terminal-based video
player (based on rxvt-unicode). I toyed with the diea of using F<mpv>'s
subtitle engine to create the user interface, but that is hard to use
since you don't know how big your letters are. It is also where most of
this modules code has originally been developed in.
It uses a unified input queue to handle various remote controls, so its
event handling needs are very simple - it simply feeds all events into the
input queue:
my $mpv = AnyEvent::MPV->new (
mpv => $MPV,
In the "start-file" event, we again set the "pause" property to "no" so
the movie starts playing. For the "end-file" event, we tell the main
program to quit by invoking $quit.
This should conclude the basics of operation. There are a few more
examples later in the documentation.
ENCODING CONVENTIONS
As a rule of thumb, all data you pass to this module to be sent to mpv
is expected to be in unicode. To pass something that isn't, you need to
escape it using "escape_binary".
Data received from mpv, however, is *not* decoded to unicode, as data
returned by mpv is not generally encoded in unicode, and the encoding is
usually unspecified. So if you receive data and expect it to be in
unicode, you need to first decode it from UTF-8, but note that this
might fail. This is not a limitation of this module - mpv simply does
not specify nor guarantee a specific encoding, or any encoding at all,
in its protocol.
METHODS
$mpv = AnyEvent::MPV->new (key => value...)
Creates a new "mpv" object, but does not yet do anything. The
support key-value pairs are:
mpv => $path
warn "$_[0] $_[1]\n";
}
on_eof => $coderef->($mpv)
on_event => $coderef->($mpv, $event, $data)
on_key => $coderef->($mpv, $string)
These are invoked by the default method implementation of the
same name - see below.
$string = $mpv->escape_binary ($string)
This module excects all command data sent to mpv to be in unicode.
Some things are not, such as filenames. To pass binary data such as
filenames through a comamnd, you need to escape it using this
method.
The simplest example is a "loadfile" command:
$mpv->cmd_recv (loadfile => $mpv->escape_binary ($path));
$started = $mpv->start (argument...)
Starts mpv, passing the given arguemnts as extra arguments to mpv.
If you don't want to go to the effort of subclassing this module, you
can also specify all event handlers as constructor keys.
EXAMPLES
Here are some real-world code snippets, thrown in here mainly to give
you some example code to copy.
doomfrontend
At one point I replaced mythtv-frontend by my own terminal-based video
player (based on rxvt-unicode). I toyed with the diea of using mpv's
subtitle engine to create the user interface, but that is hard to use
since you don't know how big your letters are. It is also where most of
this modules code has originally been developed in.
It uses a unified input queue to handle various remote controls, so its
event handling needs are very simple - it simply feeds all events into
the input queue:
my $mpv = AnyEvent::MPV->new (
mpv => $MPV,
( run in 0.767 second using v1.01-cache-2.11-cpan-88abd93f124 )