Answer the question
In order to leave comments, you need to log in
How to play audio(.mp3) in python?
Hello! Which module can play music in mp3 format? Need cross platform. I tried PyQt Phonon, but it says that there is no module, although I installed it, I tried QSound but it only plays wav, what do you recommend?
Answer the question
In order to leave comments, you need to log in
pygame
import pygame
pygame.init()
song = pygame.mixer.Sound('file.mp3')
clock = pygame.time.Clock()
song.play()
while True:
clock.tick(60)
pygame.quit()
import pyglet
song = pyglet.media.load('file.mp3')
song.play()
pyglet.app.run()
import pygst
pygst.require('0.10')
import gst
import gobject
import os
mainloop = gobject.MainLoop()
pl = gst.element_factory_make("playbin", "player")
pl.set_property('uri','file://'+os.path.abspath('file.mp3'))
pl.set_state(gst.STATE_PLAYING)
mainloop.run()
convert to OGG use PyVorbis, because the MP3 decoder is not so free anymore
What if the music file is not seen by pygame?
Is this possible on pygame?:
import pygame
pygame.init()
powerup = pygame.mixer.Sound('Jeremy Blake - Powerup!.mp3')
clock = pygame.time.Clock()
def song(song):
pygame.mixer .music.stop()
song.play()
song(powerup)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question