summaryrefslogtreecommitdiff
path: root/mpv.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2024-01-22 11:52:42 +0100
committerjaseg <git@jaseg.de>2024-01-22 11:53:02 +0100
commit4e76f01ecc4c55a8dfd923a44bebd671907f944b (patch)
tree00873b2d1e747d25f0668f5c27eb386a2020b1dc /mpv.py
parent141ec7d372c8d536c208c39bb89132d69aa1b36c (diff)
downloadpython-mpv-4e76f01ecc4c55a8dfd923a44bebd671907f944b.tar.gz
python-mpv-4e76f01ecc4c55a8dfd923a44bebd671907f944b.tar.bz2
python-mpv-4e76f01ecc4c55a8dfd923a44bebd671907f944b.zip
mpv.py: Add play_bytes convenience function
Diffstat (limited to 'mpv.py')
-rw-r--r--mpv.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/mpv.py b/mpv.py
index 19f3581..1efdeb1 100644
--- a/mpv.py
+++ b/mpv.py
@@ -1981,6 +1981,17 @@ class MPV(object):
yield write
q.put(EOF)
+ def play_bytes(self, data):
+ frame = sys._getframe()
+ stream_name = f'__python_mpv_play_generator_{hash(frame)}'
+
+ @self.python_stream(stream_name)
+ def reader():
+ yield data
+ reader.unregister() # unregister itself
+
+ self.play(f'python://{stream_name}')
+
def python_stream_catchall(self, cb):
""" Register a catch-all python stream to be called when no name matches can be found. Use this decorator on a
function that takes a name argument and returns a (generator, size) tuple (with size being None if unknown).