audio: Give the Player a playpause() function

This makes it easy for others to pause if playing, or play if paused

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-08-02 10:24:12 -04:00
parent f55ecf0472
commit e24999bb2f
2 changed files with 12 additions and 0 deletions

View File

@ -100,6 +100,12 @@ class Player:
def play(self, *args):
self.playbin.set_state(Gst.State.PLAYING)
def playpause(self, *args):
if self.get_state() == Gst.State.PLAYING:
self.pause()
else:
self.play()
def play_track(self, track):
if track == self.track:
return False

View File

@ -81,6 +81,12 @@ class TestPlayer(unittest.TestCase):
play.play()
self.assertEqual(play.get_state(), Gst.State.PLAYING)
play.playpause()
self.assertEqual(play.get_state(), Gst.State.PAUSED)
play.playpause()
self.assertEqual(play.get_state(), Gst.State.PLAYING)
play.pause()
self.assertEqual(play.get_state(), Gst.State.PAUSED)