简体   繁体   中英

Play music with PyGame without display

I'm trying to get music to play using pygame, but I don't want the GUI to pop up. If I comment out the screen variable it doesn't work, but if I leave it in everything works fine (except there is the display which I don't want).

import pygame
from pygame.locals import *
pygame.init()
#screen = pygame.display.set_mode((1,1))
pygame.mixer.music.load("01 Twisted Coil.mp3")
print("Loading Music...")
pygame.mixer.music.play(-1, 0.0)
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

Download this library like so:

pip install mp3play

Then load a file and play it:

import mp3play

sound = mp3play.load('sound.mp3')
sound.play()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM