0

我有这样的代码

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 我的代码有什么问题?

4

1 回答 1

1

Looks like a bug. I did a peek into the code at https://github.com/geoffsalmon/vlc-python/blob/master/generated/vlc.py (see snippets below).

Looks like media_player_new calls libvlc_media_player_new( self ) and libvlc_media_player_new calls the native libvlc_media_player_new( ... ) function. This function returns NULL which results in None and the further code fails.

According to the doc string NULL will be returned if an error occurs. Maybe you could enable logging via the libvlc_log functions and see what's going wrong. Refer to http://www.videolan.org/developers/vlc/doc/doxygen/html/group_libvlc_log.html

EDIT: it looks like that you can set up logging via vlc.py, too. (You shouldn't need native calls then)

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

and

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)
于 2013-07-03T06:18:37.647 回答