I wanted to create a program that allows you to choose a song to play but I did it using playsound and I can't pause it..... So I used pygame and I tried to make it but it didn't work as expected. (I just started programing and I just know a little so I know I'm bad.) Can anyone arrange the code to make it work the way I meant?
Here is the code!
from pygame import mixer
def keybinds():
while True:
print("Press 'p' to pause the music")
print("Press 'r' to resume the music")
print("Press 'e' to exit the program")
#take user input
userInput = input(" ")
if userInput == 'p':
# Pause the music
mixer.music.pause()
print("music is paused....")
elif userInput == 'r':
# Resume the music
mixer.music.unpause()
print("music is resumed....")
elif userInput == 'e':
# Stop the music playback
mixer.music.stop()
print("music is stopped....")
break
#Instantiate mixer
mixer.init()
#Set preferred volume
mixer.music.set_volume(0.2)
import time
question_1 = input("Would you like to answer some questions?(Please type yes or no (don't type yeah or nah if u do it wont work)) ")
if question_1 == "yes":
print ("Ok. Loading 2 more questions and then we can continue.")
time.sleep(2)
question_2 = input("What's your name?")
print ("Ok! " + question_2)
question_3 = input("How old are you?")
print("Ok! " + question_3 + " years old")
print ("That's all! Let's start!")
question_4 = input("Choose a song:Happy Birthday Song, Alan Walker Faded, Martin Garrix Animals")
if question_4 == "Happy Birthday Song":
#Load audio file
mixer.music.load('song')
mixer.music.play()
keybinds()
time.sleep(60)
question_5 = input ("Did you enjoy the song?")
if question_5 == yes:
print ("Thx for the feedback")
elif question_5 == no:
print ("Thx for the feedback")
elif question_4 == "Faded":
mixer.music.load('song')
mixer.music.play()
keybinds()
time.sleep(60)
question_5 = input ("Did you enjoy the song?")
if question_5 == yes:
print ("Thx for the feedback")
elif question_5 == no:
print ("Thx for the feedback")
elif question_4 == "Animals":
mixer.music.load('song')
mixer.music.play()
keybinds()
time.sleep(60)
question_5 = input ("Did you enjoy the song?")
if question_5 == yes:
print ("Thx for the feedback")
elif question_5 == no:
print ("Thx for the feedback")
elif question_1 == "no":
print ("ur lazy...ok anyways let's begin!..")
question_4 = input("Choose a song:Happy Birthday Song, Alan Walker Faded, Martin Garrix Animals")
if question_4 == "Happy Birthday Song":
mixer.music.load('song')
mixer.music.play()
keybinds()
time.sleep(60)
question_5 = input ("Did you enjoy the song?")
if question_5 == yes:
print ("Thx for the feedback")
elif question_5 == no:
print ("Thx for the feedback")
elif question_4 == "Faded":
mixer.music.load('song')
mixer.music.play()
keybinds()
time.sleep(60)
question_5 = input ("Did you enjoy the song?")
if question_5 == yes:
print ("Thx for the feedback")
elif question_5 == no:
print ("Thx for the feedback")
elif question_4 == "Animals":
mixer.music.load('song')
mixer.music.play()
keybinds()
time.sleep(60)
question_5 = input ("Did you enjoy the song?")
if question_5 == yes:
print ("Thx for the feedback")
elif question_5 == no:
print ("Thx for the feedback")