为什么我的PyGame混音器不播放声音? [英] Why doesn't my PyGame mixer play sounds,?

查看:231
本文介绍了为什么我的PyGame混音器不播放声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的2.7中的PyGame混音器不能与声音选项一起使用.我可以使它与mixer.music一起工作,但不能与mixer.sound一起工作,而与mixer.sound一起工作时,它会发出很小的滴答声,然后停止.代码:

My PyGame mixer in 2.7 won't work with the sound option. I can make it work with mixer.music but not with mixer.sound, with mixer.sound it makes a small ticking noise and then stops. Code:

import pygame
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
song = pygame.mixer.Sound("song.mp3")
pygame.mixer.Sound.play(song)

没有错误,它不会播放并发出很小的滴答声. 在Windows 7-x64 btw上.

No error, it just won't play and gives a small ticking noise. On windows 7-x64 btw.

推荐答案

通常,Pygame将不会播放mp3文件.您可以测试一下是否首先播放.wav和.ogg文件,以确保您的代码正确(基于您粘贴的内容,似乎是正确的).我建议将Pygame的mp3声音转换为ogg.

Usually, Pygame will not play mp3 files. You could test to see if .wav and .ogg files will play first, to make sure your code is correct (based on what you pasted, it seems to be right). I suggest converting your mp3 sounds to ogg for Pygame.

这篇关于为什么我的PyGame混音器不播放声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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