我正在编写一个与 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_())