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

Commits:
47c33bbe by Philipp Hörist at 2017-07-19T13:16:27+02:00
Play sounds on MacOS

- - - - -


1 changed file:

- gajim/common/helpers.py


Changes:

=====================================
gajim/common/helpers.py
=====================================
--- a/gajim/common/helpers.py
+++ b/gajim/common/helpers.py
@@ -51,15 +51,23 @@ from string import Template
 from common.i18n import Q_
 from common.i18n import ngettext
 
-if os.name == 'nt':
+HAS_SOUND = True
+if sys.platform == 'win32':
     try:
-        HAS_WINSOUND = True
         import winsound  # windows-only built-in module for playing wav
     except ImportError:
-        HAS_WINSOUND = False
+        HAS_SOUND = False
         print('Gajim is not able to playback sound because'
               'pywin32 is missing', file=sys.stderr)
 
+elif sys.platform == 'darwin':
+    try:
+        from AppKit import NSSound
+    except ImportError:
+        HAS_SOUND = False
+        print('Gajim is not able to playback sound because'
+              'pyobjc is missing', file=sys.stderr)
+
 try:
     import wave     # posix-only fallback wav playback
     import ossaudiodev as oss
@@ -764,7 +772,7 @@ def play_sound_file(path_to_soundfile):
     path_to_soundfile = check_soundfile_path(path_to_soundfile)
     if path_to_soundfile is None:
         return
-    elif sys.platform == 'win32' and HAS_WINSOUND:
+    elif sys.platform == 'win32' and HAS_SOUND:
         try:
             winsound.PlaySound(path_to_soundfile,
                     winsound.SND_FILENAME|winsound.SND_ASYNC)
@@ -785,6 +793,10 @@ def play_sound_file(path_to_soundfile):
         player = gajim.config.get('soundplayer')
         command = build_command(player, path_to_soundfile)
         exec_command(command)
+    elif sys.platform == 'darwin' and HAS_SOUND:
+        sound = NSSound.alloc()
+        sound.initWithContentsOfFile_byReference_(path_to_soundfile, True)
+        sound.play()
 
 def get_global_show():
     maxi = 0



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/47c33bbe392fbdc54dfb898203a45eb026ea5c7f
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to