* edit katrain/__main__.py * delay / 0 * edit katrain/core/constants.py * edit ENGINE.md * fix bug * fix bug * fix scroll variations * edit katrain/core/sgf_parser.py, edit tests/test_parser.py and 4 other changes * fix touchscreen * antimirror * openssl dir try * openssl dir try * fix log * openssl * auto version in osx * edit .github/workflows/osxbuild.yaml * edit .github/workflows/osxbuild.yaml * edit katrain/KataGo/katago * better pondering * new downloads * middle click add variation * change middle click pv * more tweaks * black Co-authored-by: Sander Land <sander.land@futurefacts.nl> Co-authored-by: Sander Land <sander.land@cognite.com> Co-authored-by: Sander Land <sander@chatdesk.com>
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
from kivy.clock import Clock
|
|
from kivymd.app import MDApp
|
|
from kivy.core.audio import SoundLoader
|
|
from kivy.utils import platform
|
|
|
|
cached_sounds = {}
|
|
|
|
# prefer ffpyplayer on linux, then others, avoid gst and avoid or ffpyplayer on windows
|
|
ranking = [("ffpy", 98 if platform in ["win", "macosx"] else -2), ("sdl", -1), ("gst", 99), ("", 0)]
|
|
try:
|
|
SoundLoader._classes.sort(key=lambda cls: [v for k, v in ranking if k in cls.__name__.lower()][0])
|
|
except Exception as e:
|
|
print("Exception sorting sound loaders: ", e) # private vars, so could break with versions etc
|
|
|
|
|
|
def play_sound(file, volume=1, cache=True):
|
|
def _play(sound):
|
|
if sound:
|
|
sound.play()
|
|
sound.seek(0)
|
|
|
|
app = MDApp.get_running_app()
|
|
if app and app.gui and app.gui.config("timer/sound"):
|
|
sound = cached_sounds.get(file)
|
|
if sound is None:
|
|
sound = SoundLoader.load(file)
|
|
if cache:
|
|
cached_sounds[file] = sound
|
|
if sound is not None:
|
|
sound.volume = volume
|
|
Clock.schedule_once(lambda _dt: _play(sound), 0)
|
|
|
|
|
|
def stop_sound(file):
|
|
sound = cached_sounds.get(file)
|
|
if sound:
|
|
sound.stop()
|