简体   繁体   English

Pygame 混音器.音乐无法读取 mp3 stream

[英]Pygame mixer.music can't read mp3 stream

I am trying to make my own music player with Python, and after looking at alternatives, I've settled on using pygame's mixer.music to actually play the audio.我正在尝试使用 Python 制作自己的音乐播放器,在查看了替代品之后,我决定使用 pygame 的 mixer.music 来实际播放音频。 (I've used pygame before, just usually for actual games) I was looking at playsound instead until I realized I needed a way to play the next song once one is done, as well as the ability to play and pause the audio. (我之前使用过 pygame,通常只用于实际游戏)我一直在看 playsound,直到我意识到我需要一种方法来播放下一首歌曲,以及播放和暂停音频的能力。 I also need to play mp3 files instead of the wavs that most alternatives require.我还需要播放 mp3 文件,而不是大多数替代品需要的 wav。 I actually got it working perfectly originally, until I tried adding other unrelated features, and now it's saying:实际上,我最初让它完美地工作,直到我尝试添加其他不相关的功能,现在它说:

File "main.py", line 66, in playCurrentSong
mixer.load(path.join(museDir, currentSong))
pygame.error: Error reading the stream. (code 18)

( museDir is my variable for the directory that music files are in, and mixer is my variable for pygame.mixer.music as a shorthand) museDir是音乐文件所在目录的变量, mixerpygame.mixer.music的变量作为简写)

I cannot figure out for the life of me why it's giving me this error now, as it played the audio perfectly fine before.我一生都无法弄清楚为什么它现在给我这个错误,因为它之前播放的音频非常好。 My code is here: https://pastebin.com/V7nAfmK6我的代码在这里: https://pastebin.com/V7nAfmK6

If a solution only works on a certain operating system, my final OS will be Linux, on a Rasperry Pi, but I'm trying to write and test the code on Windows.如果解决方案仅适用于某个操作系统,我的最终操作系统将是 Linux,在 Rasperry Pi 上,但我正在尝试在 Windows 上编写和测试代码。 However, if that's not possible, I understand.但是,如果那不可能,我理解。

Thank you beforehand for any and all help;预先感谢您的任何帮助; this is giving me a headache.这让我很头疼。

I just found the source of the problem.我刚刚找到了问题的根源。

Before the error popped up, I had been trying to mess around with the metadata of the mp3 files in order to incorporate a genre system into the player, but nothing was working.在错误弹出之前,我一直试图弄乱 mp3 文件的元数据,以便将流派系统合并到播放器中,但没有任何效果。 I eventually decided to use csv files for that instead.我最终决定改用 csv 文件。

I must have done something wrong however when I was messing around with that metadata because I looked at the mp3s in File Explorer, and they were all 0 bytes.但是,当我在处理该元数据时,我一定做错了什么,因为我在文件资源管理器中查看了 mp3,它们都是 0 字节。 That's why pygame couldn't read the stream: there wasn't one, I plugged the pygame stuff back in, replaced the mp3s with new ones.这就是为什么 pygame 无法读取 stream 的原因:没有,我插入了 pygame 的东西,用新的替换了 mp3。 and it works just fine now.现在它工作得很好。

Thanks for the help anyway though, Torxed!无论如何,感谢您的帮助,Torxed!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM