audio: Give the player a pause-on-load property

Setting this to True will cause the Player to change state to PAUSED
during the next emission of the "file-loaded" signal.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2023-04-26 22:38:25 -04:00
parent 9a3d095081
commit 7d26d89405
2 changed files with 18 additions and 0 deletions

View File

@ -35,6 +35,8 @@ class Player(GObject.GObject):
playtime = GObject.Property(type=float)
savedtime = GObject.Property(type=float)
pause_on_load = GObject.Property(type=bool, default=False)
def __init__(self):
"""Initialize the audio Player."""
super().__init__()
@ -140,6 +142,7 @@ class Player(GObject.GObject):
self.set_property(tag, 0)
self.almost_done = False
self.pause_on_load = False
self.artwork = artwork
self.duration = duration
@ -213,6 +216,8 @@ class Player(GObject.GObject):
def file_loaded(self, file: pathlib.Path) -> None:
"""Signal that a new URI has started."""
print("audio: file loaded")
if self.pause_on_load:
self._playbin.set_state(Gst.State.PAUSED)
(res, dur) = self._playbin.query_duration(Gst.Format.TIME)
cover = self.file.parent / "cover.jpg"
self.__reset_properties(duration=(dur / Gst.USECOND if res else 0),

View File

@ -347,6 +347,19 @@ class TestAudio(unittest.TestCase):
emmental.tmpdir.cover_jpg())
self.assertTrue(expected.is_file())
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_pause_on_load(self, mock_stdout: io.StringIO):
"""Test pausing the next time a file is loaded."""
self.assertFalse(self.player.pause_on_load)
self.player.pause_on_load = True
self.player.file = tests.util.TRACK_OGG
self.player.play()
self.main_loop()
self.assertFalse(self.player.playing)
self.assertFalse(self.player.pause_on_load)
def test_shutdown(self):
"""Test that the shutdown function works as expected."""
self.player.shutdown()