0

I'm making a program which when the player dies, gets the music time, and plays a new song using the music time from the previous song, I've done this before a while back and it worked with no problems, but now it's giving me an error message (shown below)

    musictime = pygame.mixer.music.get_pos()
    pygame.mixer.music.stop()
    pygame.mixer.music.load("music3slow.ogg")
    pygame.mixer.music.set_pos(musictime * 2)
    pygame.mixer.music.play()

the error I got was this:

AttributeError: 'module' object has no attribute 'set_pos'

I don't know what I'm doing wrong, like I said it worked when I tried it before, it's probably something stupid but sometimes you just need the eyes of somebody else to see where you've messed up, thanks in advance :)

guisantogui
  • 4,017
  • 9
  • 49
  • 93
user3254643
  • 11
  • 1
  • 3
  • 1
    It's listed in the [pygame docs](http://www.pygame.org/docs/ref/music.html) (version 1.9), but I can't find it in my module (version 1.8), too. Maybe you were using a newer version of pygame back then? – tobias_k Jan 30 '14 at 19:21
  • I'm still using the same version of python and pygame; literally nothing has changed :( – user3254643 Jan 30 '14 at 19:22
  • See if running this from the command line works: `python -c "import pygame; print(pygame.mixer.music.set_pos)"`. That should give the same traceback. If not, something really weird is going on. – Cody Piersall Jan 30 '14 at 19:25
  • python 2.7 with the latest supported version of pygame, i cant remember the version number for pygame right now – user3254643 Jan 30 '14 at 19:26
  • @user3254643 - Use [`pygame.version.ver`](http://www.pygame.org/docs/ref/pygame.html#pygame.version.ver) to get the version number. –  Jan 30 '14 at 19:28
  • @iCodez pygame 1.9.1 – user3254643 Jan 30 '14 at 19:31
  • did you checked, you are not using `pygame.mixer.xxx.set_pos()` anywhere else, with a typo or something? probably problem is not it but still, better to check. – Lafexlos Jan 30 '14 at 19:58
  • @Lafexlos just checked and this is the only time i've used it – user3254643 Jan 30 '14 at 20:01
  • FIXED IT GUYS, for some reason set_pos() still doesnt work but I figured out doing pygame.mixer.music.play(0,(musictime / 1000) * 2) did the same thing I wanted it to! Thanks for your help :) – user3254643 Jan 30 '14 at 20:24
  • That's good to hear. :) I am no expert in here but I think you should answer your own question and accept it. It will be much better than staying as "unanswered". – Lafexlos Feb 02 '14 at 21:24

2 Answers2

1

if set_pos() doesn't work try

pygame.mixer.music.play(0,(put what you need here)

I don't know why set_pos() sometimes doesn't work but the play option will and it does the same thing as set_pos

user3254643
  • 11
  • 1
  • 3
1

set_pos doesn't exist because it's a new method in 1.9.2. You have pygame version 1.9.1 according to your comments.

from https://www.pygame.org/docs/ref/music.html#pygame.mixer.music.set_pos

pygame.mixer.music.set_pos()

... description...

Function set_pos() calls underlining SDL_mixer function Mix_SetMusicPosition.

New in Pygame 1.9.2

gramonov
  • 527
  • 4
  • 12