Tushar
Tushar

Reputation: 97

Pygame - Music is not looping correctly

I am trying to loop music, but it doesn't loop correctly. For eg. If i write

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

Then it will only loop 3 times, if i pass 6 or 7, it loops 4 times, for 10 it loops 6 times, for 15 it loops 8 times and so on. I have tried different mp3 files but the result is the same. Although passing '-1' to loop infinitely works perfectly. What seems to be the problem here?

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()

Upvotes: 0

Views: 671

Answers (1)

Wboy
Wboy

Reputation: 2552

I just installed pygame and created an .ogg to debug your code.

It works fine on my computer. I.e. calling music.play(15) loops it 15 times.

I suspect that your input music file is incorrect, pygame only accepts proper .ogg files and not mp3s. Could you try a different file, converted with http://audio.online-convert.com/convert-to-ogg and see if it works?

Upvotes: 1

Related Questions