0

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

  • Maybe you can refer this https://stackoverflow.com/questions/57158779/how-to-stop-audio-with-playsound-module – Piyush Patil Apr 21 '22 at 12:24
  • The Playsound library offers exactly one function: play a sound. No pause, resume or stop. You will need a lib with more features to reach your goal. – Klaus D. Apr 21 '22 at 12:29
  • You could use os.kill with SIGSTOP and SIGCONT, but it seems really overkill. Have you any way to get the position of the current player? To restart at the given place? In such a case, you could stop the process and start it again at the previous position. – Floh Apr 21 '22 at 12:31
  • Well thanks for the answer. But finally I found the solution for may problem. Instead of using multiprocessing and playsound module in python, im using pygame.music module to do the task. It has more usefull function than playsoung – HahahaHihihi Jul 01 '22 at 06:26

0 Answers0