Skip to content Skip to sidebar Skip to footer

Python Vlc Script Error: Attributeerror: 'nonetype' Object Has No Attribute 'media_player_new'

I'm trying to make a simple script that will play a video (.mp4) in python. I don't want to play a you tube video or anything online, just a video on my computer. Here's my code: i

Solution 1:

I solved the problem by comment out find_lib() in vlc.py.

p = os.getcwd()
os.chdir(os.path.join(p, 'sdk'))
dll = ctypes.CDLL("libvlc.dll")
plugin_path = os.path.join(os.getcwd(), r'sdk\plugins')

Solution 2:

You are not holding the instance open

importvlcInstance= vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new('2005.mp3')
Media.get_mrl()
player.set_media(Media)
player.play()
while player.get_state() !=6:
    continue

Should work or try this:

import vlc
import time
import sys

defprogressbar(progress,guage_length=50):
    div = 100 / float(guage_length)
    prog = int(progress / div) # ensure progress fits in guage
    text = "\rPlaying: {0}{1}{2} [{3}%]".format(">"*prog,"|","-"*(guage_length - prog),format(progress,'.2f'))
    sys.stdout.write(text)
    sys.stdout.flush()

instance = vlc.Instance()
player = instance.media_player_new()
player.set_mrl("V2.mp4")
player.play()
playing = set([1,2,3,4])
play=True
guage_length=30while play == True:
    time.sleep(0.5)
    play_state = player.get_state()
    if play_state in playing:
        length = player.get_length()
        ptime = player.get_time()
        progress = ptime/float(length)*100
        progressbar(progress,guage_length)
        continueelse:
        progressbar(100,guage_length)
        play = Falseprint ("\nPlay terminated")

Note that # State 0: None,1 Opening,2 Buffering,3 Playing,4 Paused,5 Stopped,6 Ended,7 Error

Caveat: tested on Linux only

Solution 3:

You could simplify your code using simply

importvlcp= vlc.MediaPlayer('2005.mp3')
p.play()

but this would not solve your problem. Apparently, the vlc instance is not correctly created. This can be caused by a variety of issues. Use

i = vlc.Instance('--verbose 3')

to see possible error messages.

Solution 4:

I got this error message on a Raspberry Pi Zero with Raspbian Buster Lite. I searched a long time for the answer but suddenly I noticed the remark on the pypi project page of python-vlc:

Note that it relies on an already present install of VLC.

So installing vlc with sudo apt install vlc solved the problem!

Post a Comment for "Python Vlc Script Error: Attributeerror: 'nonetype' Object Has No Attribute 'media_player_new'"