Fixed sound.py when there are multiple sessions trying to load the library

This commit is contained in:
Manuel Cortez 2017-06-17 21:39:39 -05:00
parent d4b410cafd
commit 80f2e8f984

View File

@ -22,6 +22,8 @@ import tempfile
import glob
URLPlayer = None
is_created = False
def setup():
global URLPlayer
if not URLPlayer:
@ -58,14 +60,17 @@ class soundSystem(object):
def __init__(self, soundConfig):
""" Sound Player."""
global is_created
self.config = soundConfig
# Set the output and input default devices.
if is_created == False:
try:
self.output = Output()
self.input = Input()
except IOError:
pass
# Try to use the selected device from the configuration. It can fail if the machine does not has a mic.
if is_created == False:
try:
log.debug("Setting input and output devices...")
self.output.set_device(self.output.find_device_by_name(self.config["output_device"]))
@ -74,7 +79,7 @@ class soundSystem(object):
log.exception("Error in input or output devices, using defaults...")
self.config["output_device"] = "Default"
self.config["input_device"] = "Default"
is_created = True
self.files = []
self.cleaner = RepeatingTimer(60, self.clear_list)
self.cleaner.start()