Search code examples
python-3.xvlcattributeerrorlibvlc

AttributeError: 'NoneType' object has no attribute 'media_player_new'


I want to use vlc in python but I always have that error:

Traceback (most recent call last):
  File "radio.py", line 3, in <module>
    media = vlc.MediaPlayer('annonce.mp4')
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\vlc.py", line 3310, in __new__
    o = instance.media_player_new()
AttributeError: 'NoneType' object has no attribute 'media_player_new'

And my code :

import vlc

media = vlc.MediaPlayer('annonce.mp4')
media.play()

My video is in my program file and I use Python 3.8.3.


Solution

  • This is the absolute barebones method to get this working:

    import vlc
    import time
    
    playing = set([1,2,3,4])
    media = vlc.MediaPlayer('/home/rolf/Brassic01.mp4')
    media.play()
    while media.get_state() in playing:
        time.sleep(0.5)
    

    The instantiating of the vlc instance is performed for you, when using MediaPlayer.
    You must loop while the instance is playing, thus we check the state.
    If you are getting complaints about no attribute I would suggest that either you're missing a working version of vlc itself or there is a problem with your copy of vlc.py.

    • Ensure that you can run vlc from the command line
    • Get a current copy of vlc.py and place it in the same directory as your program

    getting vlc.py:

    or