如何在 PyGame 中一次播放多首歌曲? [英] How can I play more than one song at a time in PyGame?

查看:178
本文介绍了如何在 PyGame 中一次播放多首歌曲?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在已经开始工作了,但有时间延迟有更好的方法,因为我想要两个不同的脚本工作我想让这些按这个顺序播放并让我的图像按顺序出现并且图像是一个很长的脚本,并且也有时间延迟.

I've got it working now but with the time delay is there a better way because I want two different scripts to be working I want to have these playing in this order and have my images come up in order and the images are a long script and have time delays on them too.

#!/usr/bin/env python
import pygame
pygame.mixer.init()
pygame.mixer.pre_init(44100, -16, 2, 2048)
pygame.init()
print "hey I finaly got this working!"
sounda= pygame.mixer.Sound('D:/Users/John/Music/Music/FUN.OGG')
soundb= pygame.mixer.Sound('D:/Users/John/Music/Music/Still Alive.OGG')
soundc= pygame.mixer.Sound('D:/Users/John/Music/Music/turret.OGG')
soundd= pygame.mixer.Sound('D:/Users/John/Music/Music/portalend.OGG')
sounda.play()
pygame.time.delay(11000)
soundb.play()<P>
pygame.time.delay(180000)
soundc.play()
pygame.time.delay(90000)
soundd.play()

推荐答案

您是否检查了 pygame.混合器模块?默认情况下,您可以同时播放 8 首歌曲

Did you check the pygame.Mixer module ? On default, you can play 8 songs simultaneously

如果您使用 pygame.mixer.music,您将能够一次只播放一首歌.

If you use the pygame.mixer.music, you'll be able to play only one song at the time.

如果您使用 pygame.mixer.sound,您一次最多可以播放 8 首歌曲.

If you use the pygame.mixer.sound, you'll be able to play up to 8 songs at the time.

音乐模块用于流式传输音乐(它不会加载所有音乐文件一次).

The music module is here to stream music (it doesn't load all the music file at once).

声音模块用于在游戏中播放不同的声音游戏(声音完全加载到内存中).

The sound module is here to play differents sounds during game (sounds are completely loaded in memory).

因此,在您的示例中,如果您想同时播放 4 首歌曲:

So, in your example if you want to play the 4 songs at the same time :

import pygame
pygame.mixer.init()
pygame.mixer.pre_init(44100, -16, 2, 2048)
pygame.init()
print "hey I finaly got this working!"
sounds = []
sounds.append(pygame.mixer.Sound('D:/Users/John/Music/Music/FUN.OGG'))
sounds.append(pygame.mixer.Sound('D:/Users/John/Music/Music/Still Alive.OGG'))
sounds.append(pygame.mixer.Sound('D:/Users/John/Music/Music/turret.OGG'))
sounds.append(pygame.mixer.Sound('D:/Users/John/Music/Music/portalend.OGG'))
for sound in sounds:
    sound.play()

这篇关于如何在 PyGame 中一次播放多首歌曲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆