[vlc] vlc and qgraphicsitem
crichter at web.de
crichter at web.de
Fri Jun 10 08:50:12 CEST 2011
In the code below I tried to implement a VLC player with PyQt.
Unfortunately the video will not displayed (ton is available)
If I use the QGraphicsview as parent for the frame widget, the proxy widget can not embedded in the graphicsscene, but will be shown correctly.
Does anybody have an idea to solve this issue?
best regards,
Christian
#!/usr/bin/env python
import sys
from PyQt4.QtCore import QDir, QStringList, Qt
from PyQt4.QtGui import QApplication, QGraphicsScene, QGraphicsProxyWidget, QGraphicsView, QPainter, QPixmap, QGraphicsView, QBrush, QPalette, QFrame
from PyQt4.QtOpenGL import QGLWidget
from PyQt4.QtWebKit import QWebView
from PyQt4.phonon import Phonon
import vlc,os
import qrc_resources # compiled videowall.qrc by pyrcc4
APPNAME = 'Embedded QWebView and VideoWidget (Video Background)'
VIDEOFILE = '/media/test//Audio-Video/baguetteboden.mpg'
HTMLCODE = u"""
<html>
<head><style type="text/css"><!--
body {
background-color: transparent;
color:red;
}
--></style></head>
<body>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
Test Test sdfsdfsdfsdfsdaf df sdfsdfskdfjslkjf sfk sfsdflkflf fslf <br/>
</body>
</html>
"""
def main():
app = QApplication(sys.argv)
app.setApplicationName(APPNAME)
scene = QGraphicsScene()
view = QGraphicsView()
### VideoWidget
###############
frame = QFrame()
# frame = QFrame(view)
# frame.setAttribute(Qt.WA_NativeWindow)
video = QFrame(frame)
video.resize(400,300)
video.show()
movieName = os.path.normcase(VIDEOFILE)
instance=vlc.Instance()
player=instance.media_player_new()
vlcMedia = instance.media_new_path(movieName)
player.set_media(vlcMedia)
vlcMedia.parse()
proxy_video = scene.addWidget(frame)
proxy_video.setObjectName('proxy_video')
frame.resize(video.size())
# proxy_video.resize(600, 480)
proxy_video.show()
#hwnd = int(video.winId())
# print int(proxy_video.widget().winId())
hwnd = int(frame.winId())
# the media player has to be 'connected' to the QFrame
# (otherwise a video would be displayed in it's own window)
# this is platform specific!
# you have to give the id of the QFrame (or similar object) to
# vlc, different platforms have different functions for this
if sys.platform == "linux2": # for Linux using the X Server
player.set_xwindow(hwnd)
elif sys.platform == "win32": # for Windows
player.set_hwnd(hwnd)
elif sys.platform == "darwin": # for MacOS
player.set_agl(hwnd)
player.play()
proxy_video.setZValue(5.0)
### WebView
###########
webview = QWebView()
# ensure transparent background
palette = webview.palette()
palette.setBrush(QPalette.Base, Qt.transparent)
webview.page().setPalette(palette)
#webview.setAttribute(Qt.WA_OpaquePaintEvent, False)
webview.setAttribute(Qt.WA_OpaquePaintEvent, True)
#webview.setAttribute(Qt.WA_NoSystemBackground, True)
proxy_web = QGraphicsProxyWidget()
proxy_web.setObjectName('proxy_web')
proxy_web.setWidget(webview)
proxy_web.show()
scene.addItem(proxy_web)
webview.setHtml(HTMLCODE)
proxy_web.setZValue(10.0)
### Other stuff
###############
scene.setSceneRect(scene.itemsBoundingRect())
view.setScene(scene)
for item in scene.items():
print item.objectName(), item.zValue()
# OpenGL rendering enabled.
# OpenGL will speed up rendering and
# decreases CPU utilization
#view.setViewport(QGLWidget())
view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
view.setBackgroundBrush(QBrush(QPixmap(":/background.jpg")))
view.setCacheMode(QGraphicsView.CacheBackground)
view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate)
view.show()
view.setWindowTitle(APPNAME)
app.exec_()
if __name__ == '__main__':
main()
___________________________________________________________
Schon gehört? WEB.DE hat einen genialen Phishing-Filter in die
Toolbar eingebaut! http://produkte.web.de/go/toolbar
More information about the vlc
mailing list