play music using pygame but no sound

macos, pygame, python

Solution

Works well on Ubuntu 10.04 and Pygame 1.9.1.

Some things you can try:

- initialize whole pygame `pygame.init()`

- i_4_got's suggestion (create a display) `pygame.display.set_mode((200,100))`

- put a pause (tick) between play an get_busy

- poll events inside the loop `pygame.event.get()`

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)

Problem

``` 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's no sound and the program ends in like a second. Initially I didn't have the while loop until I saw the suggestions in the answers to similar questions. The program does enter the while loop on my friend's windows system, but not on my mac, and it doesn't have any sound either even on my friend's windows system. Does anybody know how to solve it?

Original source

Related problems