mpv.py: add wait_until_paused, wait_until_playing
This commit is contained in:
parent
7362f663c1
commit
759b9701c3
2 changed files with 12 additions and 4 deletions
|
|
@ -379,7 +379,7 @@ class KeyBindingTest(MpvTestCase):
|
||||||
def test_register_simple_decorator_fun_chaining(self):
|
def test_register_simple_decorator_fun_chaining(self):
|
||||||
self.m.loop = 'inf'
|
self.m.loop = 'inf'
|
||||||
self.m.play(TESTVID)
|
self.m.play(TESTVID)
|
||||||
self.m.wait_for_property('core-idle', lambda idle: not idle)
|
self.m.wait_until_playing()
|
||||||
|
|
||||||
handler1, handler2 = mock.Mock(), mock.Mock()
|
handler1, handler2 = mock.Mock(), mock.Mock()
|
||||||
|
|
||||||
|
|
@ -397,7 +397,7 @@ class KeyBindingTest(MpvTestCase):
|
||||||
def keypress_and_sync(key):
|
def keypress_and_sync(key):
|
||||||
self.m.keypress(key)
|
self.m.keypress(key)
|
||||||
self.m.frame_step()
|
self.m.frame_step()
|
||||||
self.m.wait_for_property('pause', lambda paused: paused)
|
self.m.wait_until_playing()
|
||||||
|
|
||||||
keypress_and_sync('a')
|
keypress_and_sync('a')
|
||||||
handler1.assert_has_calls([ mock.call() ])
|
handler1.assert_has_calls([ mock.call() ])
|
||||||
|
|
@ -569,7 +569,7 @@ class TestLifecycle(unittest.TestCase):
|
||||||
m = mpv.MPV(log_handler=handler)
|
m = mpv.MPV(log_handler=handler)
|
||||||
m.play(TESTVID)
|
m.play(TESTVID)
|
||||||
# Wait for playback to start
|
# Wait for playback to start
|
||||||
m.wait_for_property('core-idle', lambda x: not x)
|
m.wait_until_playing()
|
||||||
m.command("print-text", 'This is a python-mpv test')
|
m.command("print-text", 'This is a python-mpv test')
|
||||||
m.wait_for_playback()
|
m.wait_for_playback()
|
||||||
m.terminate()
|
m.terminate()
|
||||||
|
|
@ -599,7 +599,7 @@ class CommandTests(MpvTestCase):
|
||||||
self.m.property_observer('sub-text')(handler)
|
self.m.property_observer('sub-text')(handler)
|
||||||
|
|
||||||
self.m.loadfile(TESTVID)
|
self.m.loadfile(TESTVID)
|
||||||
self.m.wait_for_property('core-idle', lambda x: not x)
|
self.m.wait_until_playing()
|
||||||
self.m.sub_add('sub_test.srt')
|
self.m.sub_add('sub_test.srt')
|
||||||
|
|
||||||
self.m.wait_for_playback()
|
self.m.wait_for_playback()
|
||||||
|
|
|
||||||
8
mpv.py
8
mpv.py
|
|
@ -886,6 +886,14 @@ class MPV(object):
|
||||||
with self._playback_cond:
|
with self._playback_cond:
|
||||||
self._playback_cond.wait()
|
self._playback_cond.wait()
|
||||||
|
|
||||||
|
def wait_until_paused(self):
|
||||||
|
"""Waits until playback of the current title is paused or done."""
|
||||||
|
self.wait_for_property('core-idle')
|
||||||
|
|
||||||
|
def wait_until_playing(self):
|
||||||
|
"""Waits until playback of the current title has started."""
|
||||||
|
self.wait_for_property('core-idle', lambda idle: not idle)
|
||||||
|
|
||||||
def wait_for_property(self, name, cond=lambda val: val, level_sensitive=True):
|
def wait_for_property(self, name, cond=lambda val: val, level_sensitive=True):
|
||||||
"""Waits until ``cond`` evaluates to a truthy value on the named property. This can be used to wait for
|
"""Waits until ``cond`` evaluates to a truthy value on the named property. This can be used to wait for
|
||||||
properties such as ``idle_active`` indicating the player is done with regular playback and just idling around
|
properties such as ``idle_active`` indicating the player is done with regular playback and just idling around
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue