gpt4 book ai didi

pygame - 如何将多首歌曲/轨道加载到 pygame 中?

转载 作者:行者123 更新时间:2023-12-04 04:19:13 28 4
gpt4 key购买 nike

有没有办法将多首歌曲加载到 Pygame 中?我不是在谈论这样的音效;

crash_sound = pygame.mixer.Sound("crash.ogg")
#and
pygame.mixer.Sound.play(crash)

因为我知道你可以有多种不同的声音效果,很明显,分配给不同的变量。但是我说的是pygame中的音乐功能(这个):
pygame.mixer.music.load("chill_music.ogg")
#and
pygame.mixer.music.stop()

因为您不能将它分配给变量或任何东西,您只需将 mix.music 内容设置为一个 ogg 文件并且不能有更多。
我需要这个功能,因为它让我把它设置为“-1”值,让它一遍又一遍地播放,我很确定你不能用音效来做,但我想要两首不同的歌曲不同的层次。
我希望这是有道理的。
谢谢

最佳答案

I need this feature, because it let's me set it to a '-1' value making it play over and over again, which I'm pretty sure you can't do with the sound effect



其实, you can :

play()
begin sound playback
play(loops=0, maxtime=0, fade_ms=0) -> Channel

The loops argument controls how many times the sample will be repeated after being played the first time. ... If loops is set to -1 the Sound will loop indefinitely (though you can still call stop() to stop it).



所以你可以使用 Sound类(class)。

but I want two different songs for two different levels



没有什么能阻止您调用 pygame.mixer.music.load(...)再次使用另一个声音文件。它将停止播放当前文件并开始播放新文件。

Note:

The difference between the music playback and regular Sound playback is that the music is streamed, and never actually loaded all at once...



因此,如果您的音乐文件相当大并且您不想将它们存储在内存中,请使用 pygame.mixer.music是要走的路。如果您不介意完全加载文件,可以使用 Sound类(class)。

关于pygame - 如何将多首歌曲/轨道加载到 pygame 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59817691/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com