I am trying to create a small game in Colab and I am currently using the following code to start playing a song when the game is started (i.e. when the following cell is executed):
url = "background song url"
display(Audio(url=url, autoplay=True))
play_game()
However, at some point the user may win the game, in which case I would like the initial song to stop and the winning song to start.
I tried doing this:
if user_wins:
url = "winning song url"
display(Audio(url=url, autoplay=True))
However, this waits for the first song (the background song) to stop and then plays the winning song. I would like it to interrupt the background song. I also tried using the playsound
module and pygame
but I had some troubling installing these in Colab. Any help would be appreciated.