I found the library for music in replit python -- from replit import audio
. However, it only works by itself. That is, it cannot run code along with it.
It runs like this:
audio.play_file("music.mp3")
time.sleep(100)
However, the sleep
command, which is required for it to run (otherwise it'll "skip" the command as it runs for 0 seconds), means that no code can be run during this time. I tried to use thread
but it returns an error instead when I put it in a function and call it with thread.
Working code (music only):
from replit import audio
import time
audio.play_file("tlc.mp3")
time.sleep(100)
Error code:
from replit import audio
import time
from threading import Thread
def func1():
audio.play_file("tlc.mp3")
time.sleep(100)
def func2():
print('working.')
# do other things I want to do
if __name__ == '__main__':
Thread(target = func1).start()
Thread(target = func2).start()
It simply prints "working." with half a page of error message and no music appears. Any help would be appreciated.
Some background info: I want to make a console-based game with music in the background but cannot get it to work.