Answer the question
In order to leave comments, you need to log in
Why doesn't pygame play mp3 without display?
import pygame
pygame.init()
pygame.display.set_mode((100,200))
pygame.mixer.music.load("first.mp3")
pygame.mixer.music.play(0)
Answer the question
In order to leave comments, you need to log in
I once used this code (sound/sound.py file):
import pygame, sys
def play(song):
pygame.mixer.music.load(song)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
pos = pygame.mixer.music.get_pos()/ 1000
if __name__=='__main__':
if len(sys.argv) > 1:
song = sys.argv[1]
else:
song = 'file.mp3'
pygame.mixer.init(22050, -16, 2, 2048)
pygame.mixer.music.set_volume(2.0)
play(song)
pygame.quit()
def run(song):
import os, sys
pypath = sys.executable
os.spawnv(os.P_DETACH, pypath, ('python', 'sound/sound.py', song))
if __name__=='__main__':
song = 'sound/file.mp3'
run(song)
import play_song
play_song.run('sound/first-file.mp3')
from pygame import *
init()
from pygame import mixer
mixer.init()
song = mixer.music.load('Music2.mp3')
clock = time.Clock()
mixer.music.play(-1)
while True:
clock .tick(60)
quit() The
trick is that mp3 is loaded with load and wav and others with Sound
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question