AttributeError:"NoneType"对象没有属性"media_player_new" [英] AttributeError: 'NoneType' object has no attribute 'media_player_new'
本文介绍了AttributeError:"NoneType"对象没有属性"media_player_new"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在python中使用vlc,但我总是遇到该错误:
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'
还有我的代码:
import vlc
media = vlc.MediaPlayer('annonce.mp4')
media.play()
我的视频在程序文件中,并且我使用Python 3.8.3.
My video is in my program file and I use Python 3.8.3.
推荐答案
这是让其正常工作的绝对准系统方法:
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)
使用 MediaPlayer
时,将为您执行vlc instance
的实例化.
您必须在实例播放时循环播放,因此我们检查状态
.
如果您收到有关无属性
的投诉,我建议您是缺少 vlc
本身的有效版本,或者您的 vlc副本有问题.py
.
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
.
- 确保您可以从命令行运行
vlc
- 获取
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
获取 vlc.py
:
或