Sank6
Sank6

Reputation: 497

PyGame error when trying to load an MP3

My error is:

    pygame.mixer.music.load("ytdl.mp3")
pygame.error: Error reading the stream. (code 18)

I want to know what this means and how do I solve. I only get this error when I try to download a song using youtube-dl (but i'm sure there are some others which may cause this) and then try to load the file with pygame.mixer.music.load("ytdl.mp3").

If I just load the file from an mp3 file normally, it works fine.

If you need the code for my youtube-dl:

    options = {
    'format': 'bestaudio/best',
    'extractaudio': True,
    'audioformat': "mp3",
    'outtmpl': 'ytdl.mp3',
    'noplaylist': True,
}

with youtube_dl.YoutubeDL(options) as ydl:
    ydl.download(['http://www.youtube.com/watch?v=' + url])

Upvotes: 1

Views: 4648

Answers (1)

Prashant Mishra
Prashant Mishra

Reputation: 73

In pygame MP3 support is limited. On some systems an unsupported format can crash the program. Pygame is compatible with .ogg , .mid and mostly .wav format. Best option is to convert your audio file to .wav format by using any editing software or online converter and then load it.

pygame.mixer.music.load("ytdl.wav")

Hopefully this will solve your problem.

Upvotes: 3

Related Questions