Skip to content

Commit

Permalink
solbed imp with platforms_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
metalalchemist committed Jun 26, 2024
2 parents 5376ab8 + 2351721 commit 75c40be
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions helpers/sound_helper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
from sound_lib import stream
from sound_lib.output import Output
from sound_lib.main import BassError
Expand Down Expand Up @@ -38,3 +39,45 @@ def playsound(self, filename, block = False):
self.sound.play()
else:
self.sound.play_blocking()
=======
from sound_lib import stream
from sound_lib.output import Output
from sound_lib.main import BassError

class playsound:
def __init__(self):
try:
output = Output(device=-1)
except BassError as e:
#print(e)
if e.code == 14:
#print("Already initialized.")
Output.free()
output = Output(device=-1)
else:
pass
output.start()
# Setup:
self.output = output
self.sound = None
self.devicenames = self.output.get_device_names()
self.device = 1

def setdevice(self, device):
if device > 0 or device < len(self.devicenames):
self.device = device
else:
raise Exception("device is less than 1 or greater than the available devices.")

def playsound(self, filename, block = False):
if self.sound is not None:
if self.sound.is_playing:
self.sound.stop()
if self.device != self.output.get_device():
self.output.set_device(self.device)
self.sound = stream.FileStream(file = filename)
if not block:
self.sound.play()
else:
self.sound.play_blocking()
>>>>>>> 2351721a43d81972d7203c7824744af855653cb1

0 comments on commit 75c40be

Please sign in to comment.