-
Notifications
You must be signed in to change notification settings - Fork 3
/
music.py
42 lines (38 loc) · 1.38 KB
/
music.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import simpleaudio as sa
import os, sys
def findCurrentDir():
if getattr(sys, 'frozen', False):
datadir = os.path.dirname(sys.executable)
else:
datadir = os.path.dirname(__file__)
return datadir
curDir = findCurrentDir()
relDirPath = "save"
relPath = os.path.join("save", "savegame")
relPicklePath = os.path.join("save", "equipment")
relAssetPath = "assets"
relSoundPath = os.path.join("assets", "sound")
relAsciiPath = os.path.join("assets", "ascii")
relMusicPath = os.path.join("assets", "music")
relMetaPath = os.path.join("metasave", "meta")
relMetaDirPath = "metasave"
absDirPath = os.path.join(curDir, relDirPath)
absFilePath = os.path.join(curDir, relPath)
absPicklePath = os.path.join(curDir, relPicklePath)
absAssetPath = os.path.join(curDir, relAssetPath)
absSoundPath = os.path.join(curDir, relSoundPath)
absAsciiPath = os.path.join(curDir, relAsciiPath)
absMetaPath = os.path.join(curDir, relMetaPath)
absMetaDirPath = os.path.join(curDir, relMetaDirPath)
def playWavSound(sound, forceStop = False):
if forceStop:
sa.stop_all()
soundPath = os.path.join(absSoundPath, sound)
waveObj = sa.WaveObject.from_wave_file(soundPath)
playObj = waveObj.play()
return playObj
def runMusic(musicName):
playObj = None
while True:
if playObj is None or not playObj.is_playing():
playObj = playWavSound(musicName, forceStop=True)