#pygame set_pos and get_pos problem

17 messages · Page 1 of 1 (latest)

noble ferry
#
while active:  #while playing 
    current_time = pygame.mixer.music.get_pos()

    window.fill((0,0,0))
    #drawing buttons 
    if is_paused:
        cont_button.draw(window)
    else:
        pause_button.draw(window)

    bw_button.draw(window)
    fw_button.draw(window)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            active = False

        if event.type == pygame.MOUSEBUTTONUP:  #not gonna lie im kind of brain dead from when i was on this, so try reviewing what i did
            if pause_button.is_pressed(event):
                pygame.mixer_music.pause()
                is_paused = True    
                cont_button.changePos((650,100))
                pause_button.changePos((1000,800))
            
            elif cont_button.is_pressed(event):
                pygame.mixer_music.unpause()
                is_paused = False
                cont_button.changePos((1000,800))
                pause_button.changePos((650,100))

            if fw_button.is_pressed(event): #skip button
                if current_time + 5000 > aud.duration :
                    pygame.mixer.music.rewind()  #reloop yaheard
                    current_time = 0
                else:   
                    current_time = (current_time + 5000)/1000
                pygame.mixer.music.set_pos(current_time)
                pygame.time.delay(500) 

            if bw_button.is_pressed(event): #rewind button
                if current_time - 5000 <= 0:
                    pygame.mixer.music.rewind()
                    current_time = 0
                else:
                    current_time = (current_time - 5000)/1000
                pygame.mixer.music.set_pos(current_time)
                pygame.time.delay(500)

    current_sec = current_time/1000

My main concern is regarding the bw_button.is_pressed(event): section,, It wont rewind how I want it to rewind

#

So i tried printing the values of current sec to observe whats happening when i pressed the rewind button

#

and it would go back to 0 after subtracting 5 seconds (or 5000 milisec) AND THEN go back to the original, but I thought setting the pos manually would restart it to where it's supposed to start again

#

I can't really tell what I am doing wrong here

dire vapor
#

les gooo

#

love the comments already

dire vapor
dire vapor
#

meh wav should be fine

noble ferry
#

not going to lie i did a lot of printing and found out that current_time only get set back at a point

#

so what i did was something STUPID LIKE IT TOOK me 2 hours

#
if bw_button.is_pressed(event): #lebron james if he was playing for canucks
                if (skipVal - 2.5) + current_time <= 1:
                    skipVal = -current_time
                    pygame.mixer_music.rewind()
                else:
                    skipVal -= 2.5
                pygame.time.delay(500)
                pygame.mixer_music.set_pos(current_time + skipVal)
#

and then to visualize everything i did this

    current_sec = current_time + skipVal
dire vapor
#

if it works it works

#

¯_(ツ)_/¯

noble ferry
#

it does LMAOO

#

took me 2 hours and ill just accept that it works