Issues with the Replit Sound Library

I’m trying to get looping to work for some background music in python, and it will only play the sound file once.

backgroundMusic = audio.play_file(file_path="soundFileHere.mp3", does_loop = True, loop_count = -1)

Any help would be amazing!

Hi @EVANCOUTU , welcome to the forums
Replit audio is known to be buggy.
Do you have the line audio = true in your .replit file?

Yes I do, I’m just trying to get the looping to work. It successfully plays the file, however only one time.

Could you providebthe lik to your repl or send your cose?
Enclose your code like this:

```languagename
code here
```
1 Like
from replit import audio
from tkinter import *
from PIL import ImageTk

def quitGame():
    backgroundMusic.paused = not backgroundMusic.paused
    exit()


window = Tk()
BackgroundImage = ImageTk.PhotoImage(file='LuigiPicturePokerBackground.jpg')
background = Label(image=BackgroundImage)
background.place(x=0, y=0)
window.geometry('510x760')
button2 = Button(text='Exit', command=quitGame)
button2.grid(row=1, column=2, padx=5)
backgroundMusic = audio.play_file(file_path="Luigi's Casino - New Super Mario Bros.mp3", does_loop = True, loop_count = -1)
window.mainloop()

Hi @EVANCOUTU !
Try using the .set_loop function.

from replit import audio
from tkinter import *
from PIL import ImageTk

def quitGame():
    backgroundMusic.paused = not backgroundMusic.paused
    exit()


window = Tk()
BackgroundImage = ImageTk.PhotoImage(file='LuigiPicturePokerBackground.jpg')
background = Label(image=BackgroundImage)
background.place(x=0, y=0)
window.geometry('510x760')
button2 = Button(text='Exit', command=quitGame)
button2.grid(row=1, column=2, padx=5)
backgroundMusic = audio.play_file(file_path="Luigi's Casino - New Super Mario Bros.mp3")
backgroundMusic.set_loop(backgroundMusic.loops_remaining + 1)
window.mainloop()

This makes it play 2 times (1 from the original and 1 from the +1). You can change the value to anything, maybe 1 million is sufficient?

Sadly, it still only played once. What is up with this library?

Thank you for all the effort you’re giving in order to help me, it means a lot.

1 Like

Hi @EVANCOUTU !
Maybe try using PyAudio?

PyAudio does not work on Replit unless you have a VNC connection open.

The audio service as a whole is broken (most of the time) and unfortunately nothing is being done to fix it.

To loop a sound infinitely, don’t give a high value, but instead pass -1.

1 Like

Isn’t that what Tkinter is?

Tkinter opens a window which tells pid 1 “Oh hey, this person’s opened a window on their Repl, let me open a connection so they can see it”

Tkinter itself does not start the VNC connection.

1 Like