Move imports into function
This commit is contained in:
parent
67786dfd84
commit
584c9ff695
|
@ -61,21 +61,6 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_PRECIS_I18N = False
|
HAS_PRECIS_I18N = False
|
||||||
|
|
||||||
HAS_SOUND = True
|
|
||||||
if 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
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
log = logging.getLogger('gajim.c.helpers')
|
log = logging.getLogger('gajim.c.helpers')
|
||||||
|
|
||||||
special_groups = (_('Transports'), _('Not in Roster'), _('Observers'), _('Groupchats'))
|
special_groups = (_('Transports'), _('Not in Roster'), _('Observers'), _('Groupchats'))
|
||||||
|
@ -768,18 +753,28 @@ def play_sound_file(path_to_soundfile):
|
||||||
log.exception('Sound Playback Error')
|
log.exception('Sound Playback Error')
|
||||||
|
|
||||||
elif sys.platform == 'darwin':
|
elif sys.platform == 'darwin':
|
||||||
if not HAS_SOUND:
|
try:
|
||||||
log.error('NSSound not available')
|
from AppKit import NSSound
|
||||||
|
except ImportError:
|
||||||
|
log.exception('Sound Playback Error')
|
||||||
return
|
return
|
||||||
|
|
||||||
sound = NSSound.alloc()
|
sound = NSSound.alloc()
|
||||||
sound.initWithContentsOfFile_byReference_(path_to_soundfile, True)
|
sound.initWithContentsOfFile_byReference_(path_to_soundfile, True)
|
||||||
sound.play()
|
sound.play()
|
||||||
|
|
||||||
elif app.config.get('soundplayer') == '':
|
elif app.config.get('soundplayer') == '':
|
||||||
|
try:
|
||||||
|
import wave
|
||||||
|
import ossaudiodev
|
||||||
|
except Exception:
|
||||||
|
log.exception('Sound Playback Error')
|
||||||
|
return
|
||||||
|
|
||||||
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()
|
||||||
dev = oss.open('/dev/dsp', 'w')
|
dev = ossaudiodev.open('/dev/dsp', 'w')
|
||||||
dev.setparameters(sw * 8, nc, fr)
|
dev.setparameters(sw * 8, nc, fr)
|
||||||
dev.write(sndfile.readframes(nf))
|
dev.write(sndfile.readframes(nf))
|
||||||
sndfile.close()
|
sndfile.close()
|
||||||
|
|
Loading…
Reference in New Issue