Pause not working on my music shuffle function

26 Views Asked by At

My function shuffles an array to make music, but the pause button I started working on didnt work.

When I wanted to add a pause button, and thought keyboard interruptions might work, but it has a ton of errors when i pause with CTRL+C, and I dont even know if using the ENTER key will work to unpause it. Could someone tell me why im getting these errors and how to fix it? thanks in advance

`

# Import required module
import time
import random
import array
from playsound import playsound
a = 0
# Assign array
# here q indicates that the array
# contains signed integer
arr = array.array('q', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])


while True:
    try:
        time.sleep(1)  # do something here
        print('.')

    except KeyboardInterrupt:
        print('\nPausing...  (Hit ENTER to continue, type quit to exit.)')
        try:
            response = raw_input()
            if response == 'quit':
                break
            print('Resuming...')
        except KeyboardInterrupt:
            print('Resuming...')
            continue

print(arr[0])
print("Original array: ", arr)
def songs():
    for x in arr:
        global a
        a = 0
        if x == 1:
            a = "PartyintheUSA.mp3"
        elif x == 2:
            a = "stacysmom.mp3"
        elif x == 3:
            a = "stitches.mp3"
        elif x == 4:
            a = "photograph.mp3"
        elif x == 5:
            a = "rude.mp3"
        elif x == 6:
            a = "Callmemaybe.mp3"
        elif x == 7:
            a = "LoveStory.mp3"
        elif x == 8:
            a = "Lastnight.mp3"
        elif x == 9:
            a = "igotafeeling.mp3"
        elif x == 10:
            a = "tonighttonight.mp3"
        elif x == 11:
            a = "stereohearts.mp3"
        elif x == 12:
            a = "weareyoung.mp3"
        elif x == 13:
            a = "onecallaway.mp3"
        elif x == 14:
            a = "vivalavida.mp3"
        else:
            pass
        print(x)
        if a == 0:
            pass
        else:
            playsound(f'C:/Users/brinkdan005/Downloads/{a}')
# Shuffle arrayaaaw
# Here sample() returns a list, so we
# are typecasting list into array
arr = array.array('q', random.sample(list(arr), 14))

# Display shuffled array
print("Shuffled array: ", arr)
songs()

`

0

There are 0 best solutions below