我正在使用playsound模块来播放background_loop.mp3文件,但我无法调用其他函数或运行脚本的其他部分,直到它完成播放。
有没有一种方法可以在音乐播放时调用函数并运行脚本?
您可以使用线程来实现这一点。
from threading import Thread
# Create a new thread
# The target is the function to run
# You can also pass arguments to the function
t = Thread(target=playsound, args=["background_loop.mp3"])
# Start the thread
t.start()
# You can run more code here, that will keep going even while the background music is playing.