There's a problem with Phonon. If you try to play a
file in a format that it doesn't support, instead of failing or
simply sending the finished() signal it just does
nothing. I'll have to look more deeply into this and figure out if
it's a bug or feature or how to work-around it.
For now I just decided to use python-magic to
decide if the file is playable or not. This module uses
libmagic, the same library that the file
utility uses. But I hit a problem with it. One of its ussages is to
call magic.file() with the filename, but if the
filename contains a non-ascii character you get something like
this:
Traceback (most recent call last):
File "satyr.py", line 173, in next
self.play ()
File "satyr.py", line 128, in play
mimetype_enc= self.magic.file (self.filename)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in position 37: ordinal not in range(128)
I found a workaround. There's another usage, which is to call
magic.buffer() with a piece of data to recognize. So I
just simply open() the file, read() 4KiB
and pass the data to that function.
f= file (self.filename)
data= f.read (4096)
mimetype_enc= self.magic.buffer (data)
Now it works properly. I will file a bug report to the
file package once I resort out my mail setup (I cannot
send bugs with reportbug).