I am just writing a small python game for fun and I have a function that does the beginning narrative.
I am trying to get the audio to play in the background but unfortunately the mp3 file plays first before the function continues.
How do I get it to run in the background?
import playsound
def displayIntro():
playsound.playsound('storm.mp3',True)
print('')
print('')
print_slow('The year is 1845, you have just arrived home...')
Also, is there any way of controlling the volume of the play sound module?
I should add that I am using a Mac, and I am not wedded to using playsound, it just seems to be the only module that I can get working.
There is a library In pygame called mixer and you can add a mp3 file to the folder with the python script inside and put code like this inside:
I hope you found my answer helpful
Well you could just use pygame.mixer.music.play(x)
Playsound has an option for running in the background -> additional argument to be set to 0:
In windows:
Use winsound.SND_ASYNC to play them asynchronously
To stop playing
In mac or other platforms: You can try this Pygame/SDL
Just change
True
toFalse
(I usepython 3.7.1
)