I want to code a music player that shows guitar chords of the currently playing song. It should run on linux and if possible also on windows.
Since I just started learning python and like the gui coding with tkinter, I searched for a way to play music in python.
Platform independent audio implementations with a reasonable set of codecs seem to be sparse, but finally I found the vlc.py wrapper for libvlc.
Unfortunately I'm not getting very far. The example code tkvlc.py is running fine, but my own code with MediaListPlayer stays quiet.
My MediaListPlayer.play() just returns -1
Probably a stupid beginner mistake. Time to read the log output. But how?
I browsed the web but could not find a single example of log_set being used with libvlc python binding.
So I tried to make some sense out of the code. It seems, the class vlc.Instance defines log_set, but with wrong parameters: In Instance.log_set(self, data, p_instance): self is the instance object, but in the implementation it gets passed as the callback function with libvlc_log_set(self, data, p_instance).
A fix would be this method implementation:
Code: Select all
def log_set(self, data, cb):
return libvlc_log_set(cb, data, self)
But how do I get a valid LogCB to pass cb? Preferably one that somehow maps to the python logging module?
A code snippet showing that would be very welcome
Currently I do this
Code: Select all
self.instance = vlc.Instance()
cb = vlc.LogCb()
vlc.libvlc_log_set(cb, None, self.instance)
Traceback (most recent call last):
File "C:\Users\joba1\workspace\chordsplay\ChordsPlay\__main__.py", line 107, in main
gui = ChordsPlay.gui.Gui(program_name)
File "C:\Users\joba1\workspace\chordsplay\ChordsPlay\gui.py", line 28, in __init__
self.player = ChordsPlay.play.Play(songlist)
File "C:\Users\joba1\workspace\chordsplay\ChordsPlay\play.py", line 31, in __init__
vlc.libvlc_log_set(cb, None, self.instance)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\vlc.py", line 4097, in libvlc_log_set
return f(cb, data, p_instance)
ctypes.ArgumentError: argument 1: <class 'AttributeError'>: 'LogCb' object has no attribute '_as_parameter_'