Reputation: 21
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!
Upvotes: 0
Views: 255
Reputation: 14906
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.
Upvotes: 0