【问题标题】:Pygame - Music is not looping correctlyPygame - 音乐循环不正确
【发布时间】:2017-06-03 07:12:26
【问题描述】:

我正在尝试循环播放音乐,但无法正确循环播放。例如。如果我写

pygame.mixer.music.play(5, 0.0)

然后它只会循环 3 次,如果我通过 6 或 7,则循环 4 次,10 循环 6 次,15 循环 8 次,依此类推。我尝试了不同的 mp3 文件,但结果是一样的。尽管将“-1”传递给无限循环,但效果很好。这里似乎有什么问题?

import pygame, sys
from pygame.locals import *

pygame.init()

surface = pygame.display.set_mode((640, 480))
pygame.display.set_caption('Blop!')

pygame.mixer.music.load('blop.mp3')
pygame.mixer.music.play(15, 0.0)

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

【问题讨论】:

  • 试试 pygame.mixer.music(15)
  • @Wboy 我认为您打错了评论,因为它给出了“模块不可调用”错误。无论如何,我尝试了 pygame.mixer.music.play(15),但它仍然只循环了 8 次
  • 不,我指的是来自文档pygame.org/docs/ref/music.html 的评论。您是否在播放任何长时间静音的文件?
  • @Wboy 不,我尝试了一堆音频文件,比如警报器或雷声,它们不包含任何静音期,但结果是一样的。
  • 你能试试不播放mp3吗? stackoverflow.com/questions/34668981/…

标签: python-3.x pygame


【解决方案1】:

我刚刚安装了 pygame 并创建了一个 .ogg 来调试您的代码。

它在我的电脑上运行良好。 IE。调用 music.play(15) 循环它 15 次。

我怀疑您输入的音乐文件不正确,pygame 只接受正确的 .ogg 文件而不接受 mp3。您可以尝试使用 http://audio.online-convert.com/convert-to-ogg 转换的其他文件,看看它是否有效?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    • 2011-06-19
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多