So I got an idea to build something like mp3 player. To build that, I used multiprocessing
module provided in Python. Here is my code
import multiprocessing
from playsound import playsound
def cp():
playsound('Music.mp3') # play the music
x = multiprocessing.Process(target = cp, daemon = True)
def main():
x.start()
while True and x.is_alive:
u = input("Input: ")
print(u)
if u == "S":
x.terminate()
print("Terminated process")
break
elif u == 'P':
# questioned code
print("Process paused")
elif u == 'R':
# questioned code
print("Process resumed")
if __name__ == '__main__':
main()
The idea is, when the program is executed, the program will automatically play the Music.mp3
file. To control the program, the user must input specific keyword into it.
S
to stop the music and exit the program
P
to pause the music
R
to resuming playing the music
For now, I only know how to code the S
option. For the others, I don't have any idea how to code it. So my question is: Is there any idea how to complete the P
and R
options? Or maybe, is there any idea about how to build the program using another method besides using multiprocessing
module?
Thanks for the help