[gnome-music/wip/jfelder/volume-slider: 1/5] gstplayer: Handle volume




commit 3f9c3bca1995466277cbce11461eed6d058aeadd
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Oct 1 15:28:11 2021 +0200

    gstplayer: Handle volume

 gnomemusic/gstplayer.py | 5 +++++
 gnomemusic/player.py    | 6 ++++++
 2 files changed, 11 insertions(+)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index aaff3ed4c..74d026932 100644
--- a/gnomemusic/gstplayer.py
+++ b/gnomemusic/gstplayer.py
@@ -59,6 +59,8 @@ class GstPlayer(GObject.GObject):
         "stream-start": (GObject.SignalFlags.RUN_FIRST, None, ())
     }
 
+    volume = GObject.Property(type=float, flags=GObject.ParamFlags.READWRITE)
+
     def __init__(self, application: Application) -> None:
         """Initialize the GStreamer player
 
@@ -99,6 +101,9 @@ class GstPlayer(GObject.GObject):
         self._bus.connect("message::stream-start", self._on_bus_stream_start)
 
         self._player.connect("about-to-finish", self._on_about_to_finish)
+        self._player.bind_property(
+            "volume", self, "volume", GObject.BindingFlags.BIDIRECTIONAL
+            | GObject.BindingFlags.SYNC_CREATE)
 
         self._state = Playback.STOPPED
 
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index c0c2fa961..a0cf58d22 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -364,6 +364,7 @@ class Player(GObject.GObject):
 
     state = GObject.Property(type=int, default=Playback.STOPPED)
     duration = GObject.Property(type=float, default=-1.)
+    volume = GObject.Property(type=float, default=1.)
 
     def __init__(self, application):
         """Initialize the player
@@ -409,6 +410,11 @@ class Player(GObject.GObject):
 
         self._lastfm = application.props.lastfm_scrobbler
 
+        self._gst_player.bind_property(
+            "volume", self, "volume",
+            GObject.BindingFlags.BIDIRECTIONAL
+            | GObject.BindingFlags.SYNC_CREATE)
+
     @GObject.Property(
         type=bool, default=False, flags=GObject.ParamFlags.READABLE)
     def has_next(self):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]