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

Comparing AnyEvent-MPV/README (file contents):
Revision 1.2 by root, Sun Mar 19 23:26:01 2023 UTC vs.
Revision 1.3 by root, Mon Mar 20 12:31:31 2023 UTC

289 default implementation will call the "on_event" code reference 289 default implementation will call the "on_event" code reference
290 specified in the constructor, or do nothing if none was given. 290 specified in the constructor, or do nothing if none was given.
291 291
292 The first/implicit argument is the $mpv object, the second is the 292 The first/implicit argument is the $mpv object, the second is the
293 event name (same as "$data->{event}", purely for convenience), and 293 event name (same as "$data->{event}", purely for convenience), and
294 the third argument is the full event object as sent by mpv. See List 294 the third argument is the event object as sent by mpv (sans "event"
295 key). See List of events
295 of events <https://mpv.io/manual/stable/#list-of-events> in its 296 <https://mpv.io/manual/stable/#list-of-events> in its documentation.
296 documentation.
297 297
298 For subclassing, see *SUBCLASSING*, below. 298 For subclassing, see *SUBCLASSING*, below.
299 299
300 $mpv->on_key ($string) 300 $mpv->on_key ($string)
301 Invoked when a key declared by "->bind_key" is pressed. The default 301 Invoked when a key declared by "->bind_key" is pressed. The default
351 351
352 $mpv->bind_key ($INPUT => $string) 352 $mpv->bind_key ($INPUT => $string)
353 This is an extension implement by this module to make it easy to get 353 This is an extension implement by this module to make it easy to get
354 key events. The way this is implemented is to bind a 354 key events. The way this is implemented is to bind a
355 "client-message" witha first argument of "AnyEvent::MPV" and the 355 "client-message" witha first argument of "AnyEvent::MPV" and the
356 $string you passed. This $string is then passed ot the "on_key" 356 $string you passed. This $string is then passed to the "on_key"
357 handle when the key is proessed, e.g.: 357 handle when the key is proessed, e.g.:
358 358
359 my $mpv = AnyEvent::MPV->new ( 359 my $mpv = AnyEvent::MPV->new (
360 on_key => sub { 360 on_key => sub {
361 my ($mpv, $key) = @_; 361 my ($mpv, $key) = @_;
368 368
369 $mpv_>bind_key (ESC => "letmeout"); 369 $mpv_>bind_key (ESC => "letmeout");
370 370
371 The key configuration is lost when mpv is stopped and must be 371 The key configuration is lost when mpv is stopped and must be
372 (re-)done after every "start". 372 (re-)done after every "start".
373
374 [$guard] = $mpv->observe_property ($name => $coderef->($mpv, $name,
375 $value))
376 [$guard] = $mpv->observe_property_string ($name => $coderef->($mpv,
377 $name, $value))
378 These methods wrap a registry system around mpv's "observe_property"
379 and "observe_property_string" commands - every time the named
380 property changes, the coderef is invoked with the $mpv object, the
381 name of the property and the new value.
382
383 For a list of properties that you can observe, see the mpv
384 documentation <https://mpv.io/manual/stable/#property-list>.
385
386 Due to the (sane :) way mpv handles these requests, you will always
387 get a property cxhange event right after registering an observer
388 (meaning you don't have to query the current value), and it is also
389 possible to register multiple observers for the same property - they
390 will all be handled properly.
391
392 When called in void context, the observer stays in place until mpv
393 is stopped. In any otrher context, these methods return a guard
394 object that, when it goes out of scope, unregisters the observe
395 using "unobserve_property".
396
397 Internally, this method uses observer ids of 2**52
398 (0x10000000000000) or higher - it will not interfere with lower
399 ovserver ids, so it is possible to completely ignore this system and
400 execute "observe_property" commands yourself, whilst listening to
401 "property-change" events - as long as your ids stay below 2**52.
402
403 Example: register observers for changtes in "aid" and "sid". Note
404 that a dummy statement is added to make sure the method is called in
405 void context.
406
407 sub register_observers {
408 my ($mpv) = @_;
409
410 $mpv->observe_property (aid => sub {
411 my ($mpv, $name, $value) = @_;
412 print "property aid (=$name) has changed to $value\n";
413 });
414
415 $mpv->observe_property (sid => sub {
416 my ($mpv, $name, $value) = @_;
417 print "property sid (=$name) has changed to $value\n";
418 });
419
420 () # ensure the above method is called in void context
421 }
373 422
374 SUBCLASSING 423 SUBCLASSING
375 Like most perl objects, "AnyEvent::MPV" objects are implemented as 424 Like most perl objects, "AnyEvent::MPV" objects are implemented as
376 hashes, with the constructor simply storing all passed key-value pairs 425 hashes, with the constructor simply storing all passed key-value pairs
377 in the object. If you want to subclass to provide your own "on_*" 426 in the object. If you want to subclass to provide your own "on_*"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines