Reputation: 23
I'm trying to make a music player with PyQt4 and Phonon. The player works well for most of my music, but some MP3 files won't work.
I tried with a lot of MP3s, approximately 1 out of 10 seems to have the problem. Phonon doesn't send any error, it simply doesn't play the song. Just to be sure, I compared two songs, one working and the other not, and they use the same codec (MPEG-1 Layer 3), both are in 44100Hz and 320 kb/s, tags are in ID3v2.3, neither use any special characters in their tags or filepath, and both work correctly when I play them in WMP.
I initialize the player with :
self.player = Phonon.createPlayer(Phonon.MusicCategory)
then to launch a song, I use :
self.player.setCurrentSource(Phonon.MediaSource(path_to_file))
self.player.play()
Obviously, there must be some difference between the files, maybe in the way they were encoded (the whole album of a non-working song won't work either), but I have no clue why some files are ok and other not... Do you have an idea of what could cause the problem ?
I'm on Windows 10, running PyQt 4.11.4 and Python 2.7.15. Not sure about the Phonon version though... :-/
I think I found something though... I managed to get an error for incorrect MP3s :
"Contacts could not be connected because they do not support the same transport. (0x80040266)."
According to this post, it's caused by the file metadata, and when I did some tests, it looks like it comes from the album cover's file size. When the size is higher than ~108 KB, the MP3 doesn't work, but if I resize the image so that it's below this limit, the MP3 works...
Here's a simplified code to test with a problematic mp3 :
import sys
from functools import partial
from PyQt4.QtGui import *
from PyQt4.phonon import *
class MusicPlayer(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.player = Phonon.createPlayer(Phonon.MusicCategory)
BTN_play = QPushButton("Play")
BTN_play.pressed.connect(self.play)
self.setCentralWidget(BTN_play)
self.show()
def play(self):
path = "path/to/file.mp3"
self.player.setCurrentSource(Phonon.MediaSource(path))
self.player.play()
if __name__ == '__main__':
app = QApplication(sys.argv)
win = MusicPlayer()
sys.exit(app.exec_())
Still, I'd prefer not to edit each file metadata to correct it. Could there be a way to make Phonon ignore the cover image when parsing a file so that it doesn't make an error ?
Upvotes: 1
Views: 68