Stack Overflow Asked by droptop on January 14, 2021
After tagging an audio file with mutagen
pygame no longer seems to be able to play the file. It however loads the file successfully and the call to pygame.mixer.music.play()
throws no error. I actually use the music-tag
library which is just a wrapper around mutagen
for tagging the files. Was wondering if this is known issue.
Code for tagging
import music_tag
f = music_tag.load_file('sample.mp3')
f['title'] = 'Smells like teen spirit'
f['artwork'] = open('nirvana.jpg', 'rb').read()
f.save()
Code for playback
from pygame import mixer
mixer.init()
mixer.music.load('sample.mp3')
mixer.music.set_volume(0.7)
mixer.music.play(-1)
while True:
query = input()
if query == 'q':
mixer.music.stop()
break;
I’ve also noticed that on removal of the tags, pygame does play the file except the playback is really, really distorted and very different from the actual audio on the file. Meanwhile other mp3 players play the same file with or without tags just fine.
input ()
blocks the entire application until an input is made. Use the KEYDOWN
event to detect when q is pressed (see also Problem when using keyboard commands in pygame):
from pygame import mixer
mixer.init()
mixer.music.load('sample.mp3')
mixer.music.set_volume(0.7)
mixer.music.play(-1)
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
mixer.music.stop()
run = False
Answered by Rabbid76 on January 14, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP