Mac Book 播放不了音乐
来源:3-2 飞机大战项目搭建
Uaenanana
2019-06-15 02:28:40
你好,我按照老师的做了,为什么播放不了
pygame,sys
import constants
def main():
pass
# intialize
pygame.init()
# size of the screen
# depend on the resolution of the drawing
width, height = 480, 852
# make screen
screen = pygame.display.set_mode((width, height))
# name the window
pygame.display.set_caption("Jet Fighter")
# load backgroud pictrue
bg = pygame.image.load(constants.BG_PIC)
# load BGM
pygame.mixer.music.load(constants.BG_MUSIC)
# repeat BGM
pygame.mixer.music.play(-1)
# set volume
pygame.mixer.music.set_volume(0.2)
while True:
for event in pygame.event.get():
# exist the game
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
#draw the background pic
screen.blit(bg,bg.get_rect())
pygame.display.flip()
if __name__ == "__main__":
main()
import os # root of the project BASE_DIR = os.path.dirname(os.path.abspath(__file__)) # static files directory STATIC_DIR = os.path.join(BASE_DIR, "static_resources") # Backgound pic BG_PIC = os.path.join(STATIC_DIR, "images/background.png") # BGM BG_MUSIC = os.path.join(STATIC_DIR, "bgm/game_bg_music.mp3")
2回答
lxltom
2019-06-23
有可能和mp3的sample rate有关系,源文件好像是11khz, 我试着重新转换输出为44.1khz就可以播放了
慕猿梦
2019-06-16
同学,您好,Mac下,需要导入音乐格式为 .wav的格式,同学可将背景音乐转码
如果我的回答解决了您的疑惑,欢迎采纳!!祝学习愉快~~~~~
相似问题