2

What are the key differences between the Sound and Music classes in Pygame?

  • What are the limitations of each?
  • In what situation would one use one or the other? Is there a benefit to using them in an unintuitive way such as using Sound objects to play music files or visa-versa?
  • Are there specifically issues with channel limitations, and do one or both have the potential to be dropped from their channel unreliably?
  • What are the risks of playing music as a Sound?
2
  • What have you done to solve the problem you have? Started the bounty?
    – MikroDel
    Nov 6, 2013 at 7:15
  • @MikroDel I've done quite a lot actually... I've familiarized myself with the documentation several times and made a couple of test programs. I need an authoritative source because, being that this is such a critical, potentially game-breaking issue, I need to make absolutely sure that it is correct. Nov 6, 2013 at 14:14

2 Answers 2

4
+50

These are the main differences, as far as I understood it:

Music:

  • Play one file at once
  • Queue multiple files in a playlist
  • Have more control over this one stream: Pause it, rewind it, set endevents
  • Get more information: Get current position, get endevents

Sound:

  • Play as many files as you want
  • Play each file you loaded as many times as you want
  • Each time you play a sound, it chooses a Channel to play on. This may stop another Sound from playing

So, the Music object is indeed suited best for playing long music files, since you have more control of it.

The Sound object is suited best for playing short sound files, e. g. a walking sound or a gunshot.

However, if you want to have multiple music files play at once, you'll have to use Sound. I don't see any benefit of playing a sound as Music though, unless you want to be able to pause it.

4

Mostly from the two doc pages.

  • Use the music module to control the playback of music in the sound mixer.
  • music playback and regular Sound playback is that the music is streamed, and never actually loaded all at once.
  • The mixer system only supports a single music stream at once.
  • mixer can reserve channels, that Sound's will not automatically use
  • Sounds automatically use an available channel
  • I think sounds are also used if you may have multiple copies playing. Two gunshots may play with a delay, but still overlapped. Where as music will generally just be using one instance.

See: pygame.mixer.Channel , pygame.mixer.Sound , pygame.mixer.music

Not the answer you're looking for? Browse other questions tagged or ask your own question.