我有这样的代码
import vlc # no error
Instance = vlc.Instance() # no error
MediaPlayer = Instance.media_player_new() # error triggered here
错误消息是
Instance.media_player_new()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "vlc.py", line 895, in media_player_new
p._instance = self
AttributeError: 'NoneType' object has no attribute '_instance'
我正在使用python 2.6 我的代码有问题吗?
答案 0 :(得分:1)
看起来像个错误。我在https://github.com/geoffsalmon/vlc-python/blob/master/generated/vlc.py处查看了代码(请参阅下面的代码段)。
看起来media_player_new调用libvlc_media_player_new(self),而libvlc_media_player_new调用本机libvlc_media_player_new(...)函数。此函数返回NULL,结果为None,进一步的代码失败。
根据doc字符串,如果发生错误,将返回NULL。也许您可以通过libvlc_log函数启用日志记录,看看出了什么问题。请参阅http://www.videolan.org/developers/vlc/doc/doxygen/html/group_libvlc_log.html
编辑:看起来您也可以通过vlc.py设置日志记录。 (那时你不应该需要本地电话)
def media_player_new(self, uri=None):
"""Create a new MediaPlayer instance.
@param uri: an optional URI to play in the player.
"""
p = libvlc_media_player_new(self)
if uri:
p.set_media(self.media_new(uri))
p._instance = self
return p
和
def libvlc_media_player_new(p_libvlc_instance):
'''Create an empty Media Player object.
@param p_libvlc_instance: the libvlc instance in which the Media Player should be created.
@return: a new media player object, or NULL on error.
'''
f = _Cfunctions.get('libvlc_media_player_new', None) or \
_Cfunction('libvlc_media_player_new', ((1,),), class_result(MediaPlayer),
ctypes.c_void_p, Instance)
return f(p_libvlc_instance)