我正在编写一个与VLC接口的PySide Python应用程序。在Ubuntu上运行得很好,但是当我移动到Windows时,我甚至无法让VLC打开视频文件。
我将VideoLAN PyQt示例(http://git.videolan.org/?p=vlc/bindings/python.git;a=blob;f=examples/qtvlc.py;h=34aeedce116e05f575eb0ebffdacf8f06db80402;hb=HEAD)修剪成一个窗口和视频播放器,试图弄清楚出了什么问题,但仍然会出现此错误。即使使用打开文件对话框中的返回,我仍然会得到相同的错误。
以下是VideoLAN示例的精简版:
import sys
import vlc
import user
from ctypes import pythonapi, c_void_p, py_object
from PySide import QtGui, QtCore
class Player(QtGui.QMainWindow):
def __init__(self, master = None):
QtGui.QMainWindow.__init__(self, master)
self.setWindowTitle('Media Player')
self.instance = vlc.Instance()
self.mediaplayer = self.instance.media_player_new()
self.createUI()
def createUI(self):
self.widget = QtGui.QWidget(self)
self.setCentralWidget(self.widget)
self.videoframe = QtGui.QFrame()
self.palette = self.videoframe.palette()
self.palette.setColor(QtGui.QPalette.Window,
QtGui.QColor(0, 0, 0))
self.videoframe.setPalette(self.palette)
self.videoframe.setAutoFillBackground(True)
self.vboxlayout = QtGui.QVBoxLayout()
self.vboxlayout.addWidget(self.videoframe)
self.widget.setLayout(self.vboxlayout)
self.OpenFile()
def OpenFile(self, filename = None):
if filename is None:
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', user.home)
filename = filename[0]
if not filename:
return
print filename
self.media = self.instance.media_new(unicode(filename))
self.mediaplayer.set_media(self.media)
self.media.parse()
self.setWindowTitle(self.media.get_meta(0))
if sys.platform == 'linux2':
self.mediaplayer.set_xwindow(self.videoframe.winId())
elif sys.platform == 'win32':
pythonapi.PyCObject_AsVoidPtr.restype = c_void_p
pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object]
hWnd = pythonapi.PyCObject_AsVoidPtr(self.videoframe.winId())
self.mediaplayer.set_hwnd(hWnd)
elif sys.platform == 'darwin':
self.mediaplayer.set_agl(self.videoframe.windId())
self.mediaplayer.play()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
player = Player()
player.show()
player.resize(640, 480)
sys.exit(app.exec_())
答案 0 :(得分:2)
如果要打开文件(而不是流或其他来源),libVLC要求您使用“file:///”启动文件路径,当在Windows上的python中使用文件路径时,需要使用\ in为了逃避\(a la \')。
因此,用于调用文件的字符串应如下所示: 'file:/// C:\ Users \ Public \ Videos \ Sample Videos \ Wildlife.mwv'
另一个注意事项:如果可以的话,最好从文件路径中取出任何空格(即“样本视频”)