Try to play sound on all unix systems

sys.platform == 'linux' excludeds other unix systems, for example FreeBSD
This commit is contained in:
Philipp Hörist 2018-11-10 19:06:57 +01:00
parent 959a51c5f5
commit 67786dfd84
1 changed files with 19 additions and 15 deletions

View File

@ -767,8 +767,15 @@ def play_sound_file(path_to_soundfile):
except Exception: except Exception:
log.exception('Sound Playback Error') log.exception('Sound Playback Error')
elif sys.platform == 'linux': elif sys.platform == 'darwin':
if app.config.get('soundplayer') == '': if not HAS_SOUND:
log.error('NSSound not available')
return
sound = NSSound.alloc()
sound.initWithContentsOfFile_byReference_(path_to_soundfile, True)
sound.play()
elif app.config.get('soundplayer') == '':
def _oss_play(): def _oss_play():
sndfile = wave.open(path_to_soundfile, 'rb') sndfile = wave.open(path_to_soundfile, 'rb')
nc, sw, fr, nf, _comptype, _compname = sndfile.getparams() nc, sw, fr, nf, _comptype, _compname = sndfile.getparams()
@ -778,14 +785,11 @@ def play_sound_file(path_to_soundfile):
sndfile.close() sndfile.close()
dev.close() dev.close()
app.thread_interface(_oss_play) app.thread_interface(_oss_play)
return
else:
player = app.config.get('soundplayer') player = app.config.get('soundplayer')
command = build_command(player, path_to_soundfile) command = build_command(player, path_to_soundfile)
exec_command(command) 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(): def get_global_show():
maxi = 0 maxi = 0