diff --git a/emmental/audio/__init__.py b/emmental/audio/__init__.py index 21a9261..4659140 100644 --- a/emmental/audio/__init__.py +++ b/emmental/audio/__init__.py @@ -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), diff --git a/tests/audio/test_audio.py b/tests/audio/test_audio.py index 7be68e0..9ded546 100644 --- a/tests/audio/test_audio.py +++ b/tests/audio/test_audio.py @@ -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()