class MPVError(Exception):
| MPVError(**args, ****kwargs)
An error originating from MPV or due to a problem with MPV.
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__(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()
Terminate the thread.
| send(data)
Send data to the pipe, encoded as JSON.
| run()
Process pipe events. Do not run this directly. Use start.
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__(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()
Terminate the thread.
| send(data)
Send data to the socket, encoded as JSON.
| run()
Process socket events. Do not run this directly. Use start.
class MPVProcess()
Manages an MPV process, ensuring the socket or pipe is available. (Internal)
| __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()
Terminate the process.
class MPVInter()
Low-level interface to MPV. Does NOT manage an mpv process. (Internal)
| __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()
Terminate the underlying connection.
| event_callback(data)
Internal callback for recieving events from MPV.
| 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.
class EventHandler(threading.Thread)
Event handling thread. (Internal)
| __init__()
Create an instance of the thread.
| 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()
Terminate the thread.
| run()
Process socket events. Do not run this directly. Use start.
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__(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(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(name)
Decorator to bind a callback to an MPV event.
@on_event(name)
def my_callback(event_data):
pass
| event_callback(name)
An alias for on_event to maintain compatibility with python-mpv.
| 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(name, callback)
Bind a callback to an MPV keypress event.
name is the key symbol.
callback() is the function to call.
| 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(observer_id)
Remove callback to an MPV property change.
observer_id is the id returned by bind_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(name)
Waits for the value of a property to change.
name is the name of the property.
| play(url)
Play the specified URL. An alias to loadfile().
| terminate()
Terminate the connection to MPV and process (if start_mpv is used).
| 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.