Philipp Hörist pushed to branch master at gajim / gajim

Commits:

1 changed file:

Changes:

  • gajim/common/sound.py
    ... ... @@ -44,14 +44,24 @@ def play(self, path: Path, loop: bool = False) -> None:
    44 44
         def stop(self) -> None:
    
    45 45
             raise NotImplementedError
    
    46 46
     
    
    47
    +    def loop_in_progress(self) -> bool:
    
    48
    +        raise NotImplementedError
    
    49
    +
    
    47 50
     
    
    48 51
     class PlatformWindows(PlaySound):
    
    49 52
     
    
    53
    +    def __init__(self) -> None:
    
    54
    +        self._loop_in_progress = False
    
    55
    +
    
    50 56
         def play(self, path: Path, loop: bool = False) -> None:
    
    57
    +        if self._loop_in_progress:
    
    58
    +            return
    
    59
    +
    
    51 60
             flags = (winsound.SND_FILENAME |
    
    52 61
                      winsound.SND_ASYNC |
    
    53 62
                      winsound.SND_NODEFAULT)
    
    54 63
             if loop:
    
    64
    +            self._loop_in_progress = True
    
    55 65
                 flags = flags | winsound.SND_LOOP
    
    56 66
     
    
    57 67
             try:
    
    ... ... @@ -64,6 +74,10 @@ def stop(self) -> None:
    64 74
                 winsound.PlaySound(None, 0)
    
    65 75
             except Exception:
    
    66 76
                 log.exception('Sound Playback Error')
    
    77
    +        self._loop_in_progress = False
    
    78
    +
    
    79
    +    def loop_in_progress(self) -> bool:
    
    80
    +        return self._loop_in_progress
    
    67 81
     
    
    68 82
     
    
    69 83
     class PlatformMacOS(PlaySound):
    
    ... ... @@ -76,6 +90,9 @@ def play(self, path: Path, loop: bool = False) -> None:
    76 90
         def stop(self) -> None:
    
    77 91
             pass
    
    78 92
     
    
    93
    +    def loop_in_progress(self) -> bool:
    
    94
    +        return False
    
    95
    +
    
    79 96
     
    
    80 97
     class PlatformUnix(PlaySound):
    
    81 98
     
    
    ... ... @@ -86,8 +103,10 @@ def play(self, path: Path, loop: bool = False) -> None:
    86 103
             if not app.is_installed('GSOUND'):
    
    87 104
                 return
    
    88 105
     
    
    106
    +        if self.loop_in_progress():
    
    107
    +            return
    
    108
    +
    
    89 109
             attrs = {'media.filename': str(path)}
    
    90
    -        self._cancellable = Gio.Cancellable()
    
    91 110
     
    
    92 111
             if loop:
    
    93 112
                 self._play_loop(attrs)
    
    ... ... @@ -99,6 +118,7 @@ def play(self, path: Path, loop: bool = False) -> None:
    99 118
                     self._cancellable = None
    
    100 119
     
    
    101 120
         def _play_loop(self, attrs: dict[str, str]) -> None:
    
    121
    +        self._cancellable = Gio.Cancellable()
    
    102 122
             try:
    
    103 123
                 app.gsound_ctx.play_full(attrs,
    
    104 124
                                          self._cancellable,
    
    ... ... @@ -117,6 +137,7 @@ def _on_play_finished(self,
    117 137
             except GLib.Error as error:
    
    118 138
                 quark = GLib.quark_try_string('g-io-error-quark')
    
    119 139
                 if error.matches(quark, Gio.IOErrorEnum.CANCELLED):
    
    140
    +                self._cancellable = None
    
    120 141
                     return
    
    121 142
                 log.error('Could not play sound: %s', error.message)
    
    122 143
     
    
    ... ... @@ -128,6 +149,9 @@ def stop(self) -> None:
    128 149
             self._cancellable.cancel()
    
    129 150
             self._cancellable = None
    
    130 151
     
    
    152
    +    def loop_in_progress(self) -> bool:
    
    153
    +        return self._cancellable is not None
    
    154
    +
    
    131 155
     
    
    132 156
     def _init_platform() -> PlaySound:
    
    133 157
         if sys.platform == 'win32':