Skip to content

Commit

Permalink
play new music when song is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
adangert committed Jun 9, 2020
1 parent 1f47f3c commit cf0105b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions piaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from multiprocessing import Value
from threading import Thread
import pygame
import random
import glob
from sys import platform
if platform == "linux" or platform == "linux2":
import alsaaudio
Expand Down Expand Up @@ -109,7 +111,8 @@ def audio_loop(fname, ratio, stop_proc):
elif(fname['song'] != ''):
if(song_loaded == False):
try:
segment = AudioSegment.from_file(fname['song'])
random_song = random.choice(glob.glob(fname['song']))
segment = AudioSegment.from_file(random_song)
except:
segment = AudioSegment.from_wav("audio/Joust/music/classical.wav")

Expand Down Expand Up @@ -138,7 +141,8 @@ def ReadSamples(wf, read_size):
if len(sample) > 0:
yield sample
else:
wf.rewind()
return


# Writes incoming samples in chunks of write_size to device.
# Quits when stop_proc is set to a non-zero value.
Expand Down Expand Up @@ -172,7 +176,6 @@ def Resample(samples):
yield out_data

WriteSamples(device, PERIOD_BYTES, Resample(ReadSamples(wf, PERIOD)))
print("closing everything")
wf.close()
device.close()
song_loaded = False
Expand Down
8 changes: 4 additions & 4 deletions piparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ def __init__(self):


def choose_new_music(self):
self.joust_music.load_audio(random.choice(glob.glob("audio/Joust/music/*")))
self.zombie_music.load_audio(random.choice(glob.glob("audio/Zombie/music/*")))
self.commander_music.load_audio(random.choice(glob.glob("audio/Commander/music/*")))
self.joust_music.load_audio("audio/Joust/music/*")
self.zombie_music.load_audio("audio/Zombie/music/*")
self.commander_music.load_audio("audio/Commander/music/*")

def check_for_new_moves(self):
self.enable_bt_scanning(True)
Expand Down Expand Up @@ -581,7 +581,7 @@ def game_loop(self):
while True:
if self.play_menu_music:
self.play_menu_music = False
self.menu_music.load_audio(random.choice(glob.glob("audio/Menu/music/*")))
self.menu_music.load_audio("audio/Menu/music/*")
self.menu_music.start_audio_loop()
self.i=self.i+1
if "linux" in platform:
Expand Down

0 comments on commit cf0105b

Please sign in to comment.