Liemaeu
Liemaeu

Reputation: 31

pygame: get the current time of the music

Is there any way in pygame (Python 3) to get the "real" current playtime of the playing music file? pygame.mixer.music.get_pos() does only return how long pygame is playing the file. But when I skip forward, pygame.mixer.music.get_pos() returns the "wrong" value. So when I play the music e.g. for 10 seconds and skip to minute 1:00, then pygame.mixer.music.get_pos() returns 10 seconds instead of 1:10 minutes.

Is there any way to get the "real" current play time of the music?

(I need this for a tkinter scale bar and time label)

Upvotes: 3

Views: 1921

Answers (1)

johndoe
johndoe

Reputation: 11

use pygame.mixer.music.get_pos() / 1000

if I'm not mistaken I read that get_pos() returns a value in milliseconds

I tested it manually with a song here, and yes it works perfectly

Upvotes: 1

Related Questions