0

I have been recently working on a new game and I am finally finished with it and I was adding some music as some last touches but then I realized that the sounds were very poor quality and so I tried to make it into different extensions and wav, mp3 don't work and I was trying OGG and it says it 'failed to load'. I need help either fixing the OGG loading or fixing the poor quality given with wav and mp3. I am on windows 10 Here I load the audio files:

intro_mp3 = mixer.Sound("audio/intro.ogg")
choosing_mp3 = mixer.Sound('audio/choosing.ogg')
battle_mp3 = mixer.Sound('audio/battle.ogg')
win_mp3 = mixer.Sound('audio/win.ogg')
lose_mp3 = mixer.Sound('audio/lose.ogg')

and here I play it outside of this if statement:

if start_button.draw(screen):
        sleep(0.2)
        game_screen()
        start_button.remove()
        start.fill((0, 0, 0, 0))
        intro = True
        chosen_fighter = True
        bool_appearer = True
        print("START")
        screen.blit(tutorial, (50, 0))
    intro_mp3.play()

Please help!

Flowings
  • 21
  • 1
  • Can you elaborate on "poor quality"? How do they sound different to playing them in a stand-alone player. Also, you're using `time.sleep()` which might be causing problems, you should use a state machine / counter or a timer event. A [mcve] would make it possible to help you. – import random Jul 28 '22 at 03:38
  • 1
    Are you able to play the OGG file in a stand-alone player? – ductTapeIsMagic Jul 28 '22 at 11:37
  • "and here I play it outside of this if statement" - The `intro_mp3.play()` line is clearly located inside the if statement. Has there gone anything wrong with the indentation? – The_spider Jul 28 '22 at 11:53
  • The poor quality is describable as it echoing over and over, I am able to play it in a stand_alone player, plays fine. The spacing went wrong and in the source code everything is 1 tab behind except for the if statement – Flowings Jul 28 '22 at 14:51

1 Answers1

0

There is very little code provided in the question for analysis.

You describe the sound as "echoing over and over", this makes me believe your code is repeatedly asking the pygame.mixer.Sound object to play() the sound, without waiting for the sound to complete. Maybe it's starting a new playback every time some loop executes. Probably the design did not intend for this to happen.

Calling .Sound.play() only starts the playback, the function does not block, it returns almost immediately.

The .Sound.play() call returns the pygame.mixer.Channel object on which the sound is playing. Your code could call the .get_busy() member function on the Channel to see if the sound was still playing, and not play it a second time. (Although get_busy() returns true if any sound is playing, not just a particular one).

Obviously the best fix is re-structure the code so the sound playback is only triggered a single time.

Kingsley
  • 14,398
  • 5
  • 31
  • 53