Commit 6dacbe4c authored by André's avatar André Committed by Philipp Hörist

Use GSound to play sound on Linux

parent 60182967
Pipeline #4932 passed with stages
in 3 minutes and 14 seconds
......@@ -25,6 +25,7 @@
- gir1.2-gupnpigd-1.0 for better NAT traversing
- gir1.2-networkmanager-1.0 for network lose detection
- gir1.2-geoclue-2.0 for sharing your location
- gir1.2-gsound-1.0 for sound on Linux
### Compile-time Requirements
......
......@@ -166,6 +166,13 @@ modules:
url: https://files.pythonhosted.org/packages/b6/ec/9abe8377d9819fc0383992aaa1b8ce263b45a2371f9f30204abf61029937/precis_i18n-1.0.1-py3-none-any.whl
sha256: dc9f9fb0c080af9454adce9cc1ddcd718309f3a99ca05186f65e9f6b0654dcd9
- name: gsound
sources:
- type: git
url: https://gitlab.gnome.org/GNOME/gsound.git
tag: 1.0.2
commit: a86946b494aa32782b3f6334344d07b5c11d5219
- name: gspell
cleanup:
- /bin
......
......@@ -144,6 +144,8 @@ socks5queue = None
gupnp_igd = None
gsound_ctx = None
gajim_identity = DiscoIdentity(category='client',
type='pc',
name='Gajim')
......@@ -197,6 +199,7 @@ _dependencies = {
'GEOCLUE': False,
'UPNP': False,
'PYCURL': False,
'GSOUND': False,
'GSPELL': False,
'IDLE': False,
}
......@@ -298,6 +301,21 @@ def detect_dependencies():
except Exception:
pass
# GSOUND
try:
gi.require_version('GSound', '1.0')
from gi.repository import GLib
from gi.repository import GSound
global gsound_ctx
gsound_ctx = GSound.Context()
try:
gsound_ctx.init()
_dependencies['GSOUND'] = True
except GLib.Error as error:
log('gajim').error(error)
except (ImportError, ValueError):
pass
# GSPELL
try:
gi.require_version('Gspell', '1')
......
......@@ -115,8 +115,6 @@ class Config:
'show_ascii_formatting_chars': [opt_bool, True, _('If enabled, do not '
'remove */_ . So *abc* will be bold but with * * not removed.')],
'sounds_on': [opt_bool, True],
# 'aplay', 'play', 'esdplay', 'artsplay' detected first time only
'soundplayer': [opt_str, ''],
'gc_refer_to_nick_char': [opt_str, ',', _('Character to add after nickname when using nickname completion (tab) in group chat.')],
'gc_proposed_nick_char': [opt_str, '_', _('Character to propose to add after desired nickname when nickname is already used in group chat.')],
'msgwin-max-state': [opt_bool, False],
......
......@@ -42,7 +42,6 @@ import socket
import time
import logging
import json
import shutil
import copy
import collections
from collections import defaultdict
......@@ -453,27 +452,6 @@ def get_uf_chatstate(chatstate):
return _('has closed the chat window or tab')
return ''
def find_soundplayer():
if sys.platform in ('win32', 'darwin'):
return
if app.config.get('soundplayer') != '':
return
commands = ('aucat', 'paplay', 'aplay', 'play', 'ossplay')
for command in commands:
if shutil.which(command) is not None:
if command == 'paplay':
command += ' -n gajim --property=media.role=event'
elif command in ('aplay', 'play'):
command += ' -q'
elif command == 'ossplay':
command += ' -qq'
elif command == 'aucat':
command += ' -i'
app.config.set('soundplayer', command)
break
def exec_command(command, use_shell=False, posix=True):
"""
execute a command. if use_shell is True, we run the command as is it was
......@@ -702,28 +680,11 @@ def play_sound_file(path_to_soundfile):
sound.initWithContentsOfFile_byReference_(path_to_soundfile, True)
sound.play()
elif app.config.get('soundplayer') == '':
elif app.is_installed('GSOUND'):
try:
import wave
import ossaudiodev
except Exception:
log.exception('Sound Playback Error')
return
def _oss_play():
sndfile = wave.open(path_to_soundfile, 'rb')
nc, sw, fr, nf, _comptype, _compname = sndfile.getparams()
dev = ossaudiodev.open('/dev/dsp', 'w')
dev.setparameters(sw * 8, nc, fr)
dev.write(sndfile.readframes(nf))
sndfile.close()
dev.close()
app.thread_interface(_oss_play)
else:
player = app.config.get('soundplayer')
command = build_command(player, path_to_soundfile)
exec_command(command)
app.gsound_ctx.play_simple({'media.filename' : path_to_soundfile})
except GLib.Error as error:
log.error('Could not play sound: %s', error.message)
def get_global_show():
maxi = 0
......
......@@ -2221,8 +2221,6 @@ class Interface:
# get transports type from DB
app.transport_type = app.logger.get_transports_type()
helpers.find_soundplayer()
self.last_ftwindow_update = 0
self.music_track_changed_signal = None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment