How to start music at a specific second in Pygame

3k views Asked by At

I was looking at the API:

http://www.pygame.org/docs/ref/music.html#pygame.mixer.music.play

It says I can start the song at a certain position. However, 1 of 2 things happen. Either the song plays normally from the start or it plays really fuzzy-like. I'm not sure why I can inconsistent results either.

pygame.mixer.music.load("music/Glorious Morning 2.mp3")
#pygame.mixer.music.set_pos(52.0)#this won't work either
pygame.mixer.music.play(-1, 52.0)

I'm not sure why it's not working. Am I doing something wrong? Is there another way to start music at a specific second?

2

There are 2 answers

0
But I'm Not A Wrapper Class On BEST ANSWER

My Python version is 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]. I'm not sure what Pygame version was, but I just updated both Python and Pygame and it worked!

0
Jean-Pierre Schnyder On

Here's a working snippet tested on both Windows 10 and Android. Note that the music file is a mp3 !

import pygame.mixer

#SOUND_FILE = 'c:/temp/JMJ.mp3'
SOUND_FILE = '/storage/emulated/0/music/JMJ.mp3'

pygame.mixer.pre_init(44100, -16, 2, 2048)
pygame.mixer.init()

pygame.mixer.music.load(SOUND_FILE)
pygame.mixer.music.play(loops=0, start=1626) # 1626 seconds from beginning

while pygame.mixer.music.get_busy():
    pygame.event.wait()