Play music using pygame but without sound

import pygame pygame.mixer.init() pygame.mixer.music.load("only one.mp3") pygame.mixer.music.play(0) while pygame.mixer.music.get_busy(): pygame.time.Clock().tick(10) 

When I run the code, there is no sound, and the program ends in a second. Initially, I did not have a while loop until I saw sentences in answers to similar questions. The program does enter the while loop in my friends windows system, but not on my mac, and it has no sound even in my friends windows system. Does anyone know how to solve it?

+8
source share
5 answers

Works well on Ubuntu 10.04 and Pygame 1.9.1.

Some things you can try:

  • initialize all pygame pygame.init()
  • I_4_got clause (create a mapping) pygame.display.set_mode((200,100))
  • set pause (tick) between get_busy playback
  • polling events inside the pygame.event.get() loop

Example:

 import pygame pygame.init() pygame.display.set_mode((200,100)) pygame.mixer.music.load("only one.mp3") pygame.mixer.music.play(0) clock = pygame.time.Clock() clock.tick(10) while pygame.mixer.music.get_busy(): pygame.event.poll() clock.tick(10) 
+13
source
 import winsound winsound.PlaySound(filename [as string with path if necessary], flag [integer zB 1 for asynchronous] ) 

This works fine with Windows 8 and Python 2.7.6 and * .wav files

Various flags that you can check, enter winsound. and find the autocomplete list.
Flags are similar to SND_FILENAME or similar.
If you enter them in an editor, for example: *winsound.SND_FILENAME you get an integer to apply to the PLaySound from above

Good luck

+1
source

Pygame Sound Not Working Fix

INFO

Try reinstalling pygame or updating it . I had version 1.9.1 , which I upgraded to 1.9.3 with the following command

 pip install pygame --upgrade 

Note:


If you install it using easy_install, it does not work. Not sure, but when I tried with easy_install, it does not work.


The code is the same as yours, but I just replaced it with my music file to check it.
You can see it in the image:

In this image

.wav files seem to work well

I checked it with .mp3 files and found that it was not working. You can convert .mp3 to .wav from: Converter

Or use PyMedia
If you do not want to convert it using any website.
You can also convert it using pydub.

You can download pydub from this

link

Or enter this command at a command prompt:

 pip install pydub 
+1
source

Pygame usually does not play mp3 files. You can check if the .wav and .ogg files will play first to make sure your code is correct (depending on what you inserted, this seems to be correct). I suggest converting your mp3 sounds to OGG for Pygame.

0
source

it would be easier if you changed the mp3 format to ogg try this .. its simple

 from pygame import * pygame.init() pygame.mixer.music.load("only one.ogg") pygame.mixer.music.play(-1) pygame.mixer.music.set_volume(0.3) 

vote for the answer if its work if not tell me what is wrong

-1
source

All Articles