I use the pygame.mixer
module for my music player
While doing the project, I came across a problem that I realized was from the pygame.mixer
module
When I set the new position inside the set_pos()
function
get_pos()
function does not output the new position and outputs the initial position
from time import sleep
from pygame import mixer
mixer.init()
mixer.music.load("file.mp3")
mixer.music.play()
mixer.music.set_pos(10.0)
sleep(2)
print(mixer.music.get_pos())
output:
2000 ms
If for my logic this output is correct:
12000 ms
set_pos()
:So, you could use this code:
However, using
set_pos()
can give you errors like this, for example with.ogg
sound files:You should then prefer using
pygame.mixer.music.play(loops, start)
like this:From the docs:
As a general rule, you should be using
.ogg
files since over.mp3
since they had been implemented before and they have a move precise positioning ("For MP3 files the start time position selected may not be accurate").get_pos()
can give you weird results, as it only shows for how long the music has been playing. So, it does not take into account the fact that you "jump" a full minute if the music started playing 1 second ago. It will output you1000
(ms). Docs:Linked: pygame.error: set_pos unsupported for this codec