Skip to content

Latest commit

 

History

History
460 lines (281 loc) · 8.87 KB

docs.md

File metadata and controls

460 lines (281 loc) · 8.87 KB

python_mpv_jsonipc

MPVError

class MPVError(Exception):
 |  MPVError(**args, ****kwargs)

An error originating from MPV or due to a problem with MPV.

WindowsSocket

class WindowsSocket(threading.Thread)

Wraps a Windows named pipe in a high-level interface. (Internal)

Data is automatically encoded and decoded as JSON. The callback
function will be called for each inbound message.

__init__

 | __init__(ipc_socket, callback=None, quit_callback=None)

Create the wrapper.

ipc_socket is the pipe name. (Not including \\.\pipe\)
callback(json_data) is the function for recieving events.

stop

 | stop()

Terminate the thread.

send

 | send(data)

Send data to the pipe, encoded as JSON.

run

 | run()

Process pipe events. Do not run this directly. Use start.

UnixSocket

class UnixSocket(threading.Thread)

Wraps a Unix/Linux socket in a high-level interface. (Internal)

Data is automatically encoded and decoded as JSON. The callback
function will be called for each inbound message.

__init__

 | __init__(ipc_socket, callback=None, quit_callback=None)

Create the wrapper.

ipc_socket is the path to the socket.
callback(json_data) is the function for recieving events.

stop

 | stop()

Terminate the thread.

send

 | send(data)

Send data to the socket, encoded as JSON.

run

 | run()

Process socket events. Do not run this directly. Use start.

MPVProcess

class MPVProcess()

Manages an MPV process, ensuring the socket or pipe is available. (Internal)

__init__

 | __init__(ipc_socket, mpv_location=None, ****kwargs)

Create and start the MPV process. Will block until socket/pipe is available.

ipc_socket is the path to the Unix/Linux socket or name of the Windows pipe.
mpv_location is the path to mpv. If left unset it tries the one in the PATH.

All other arguments are forwarded to MPV as command-line arguments.

stop

 | stop()

Terminate the process.

MPVInter

class MPVInter()

Low-level interface to MPV. Does NOT manage an mpv process. (Internal)

__init__

 | __init__(ipc_socket, callback=None, quit_callback=None)

Create the wrapper.

ipc_socket is the path to the Unix/Linux socket or name of the Windows pipe.
callback(event_name, data) is the function for recieving events.

stop

 | stop()

Terminate the underlying connection.

event_callback

 | event_callback(data)

Internal callback for recieving events from MPV.

command

 | command(command, **args)

Issue a command to MPV. Will block until completed or timeout is reached.

command is the name of the MPV command

All further arguments are forwarded to the MPV command.
Throws TimeoutError if timeout of 120 seconds is reached.

EventHandler

class EventHandler(threading.Thread)

Event handling thread. (Internal)

__init__

 | __init__()

Create an instance of the thread.

put_task

 | put_task(func, **args)

Put a new task to the thread.

func is the function to call

All further arguments are forwarded to func.

stop

 | stop()

Terminate the thread.

run

 | run()

Process socket events. Do not run this directly. Use start.

MPV

class MPV()

The main MPV interface class. Use this to control MPV.

This will expose all mpv commands as callable methods and all properties.
You can set properties and call the commands directly.

Please note that if you are using a really old MPV version, a fallback command
list is used. Not all commands may actually work when this fallback is used.

__init__

 | __init__(start_mpv=True, ipc_socket=None, mpv_location=None, log_handler=None, loglevel=None, quit_callback=None, ****kwargs)

Create the interface to MPV and process instance.

start_mpv will start an MPV process if true. (Default: True)
ipc_socket is the path to the Unix/Linux socket or name of Windows pipe. (Default: Random Temp File)
mpv_location is the location of MPV for start_mpv. (Default: Use MPV in PATH)
log_handler(level, prefix, text) is an optional handler for log events. (Default: Disabled)
loglevel is the level for log messages. Levels are fatal, error, warn, info, v, debug, trace. (Default: Disabled)

All other arguments are forwarded to MPV as command-line arguments if start_mpv is used.

bind_event

 | bind_event(name, callback)

Bind a callback to an MPV event.

name is the MPV event name.
callback(event_data) is the function to call.

on_event

 | on_event(name)

Decorator to bind a callback to an MPV event.

@on_event(name)
def my_callback(event_data):
pass

event_callback

 | event_callback(name)

An alias for on_event to maintain compatibility with python-mpv.

on_key_press

 | on_key_press(name)

Decorator to bind a callback to an MPV keypress event.

@on_key_press(key_name)
def my_callback():
pass

bind_key_press

 | bind_key_press(name, callback)

Bind a callback to an MPV keypress event.

name is the key symbol.
callback() is the function to call.

bind_property_observer

 | bind_property_observer(name, callback)

Bind a callback to an MPV property change.

name is the property name.
callback(name, data) is the function to call.

Returns a unique observer ID needed to destroy the observer.

unbind_property_observer

 | unbind_property_observer(observer_id)

Remove callback to an MPV property change.

observer_id is the id returned by bind_property_observer.

property_observer

 | property_observer(name)

Decorator to bind a callback to an MPV property change.

@property_observer(property_name)
def my_callback(name, data):
pass

wait_for_property

 | wait_for_property(name)

Waits for the value of a property to change.

name is the name of the property.

play

 | play(url)

Play the specified URL. An alias to loadfile().

terminate

 | terminate()

Terminate the connection to MPV and process (if start_mpv is used).

command

 | command(command, **args)

Send a command to MPV. All commands are bound to the class by default,
except JSON IPC specific commands. This may also be useful to retain
compatibility with python-mpv, as it does not bind all of the commands.

command is the command name.

All further arguments are forwarded to the MPV command.