[PyQt] PyQT5: Unable to render videos
Rob
rob at pixelinspiration.net
Thu Mar 22 10:51:10 GMT 2018
Hi,
Bit more info on here with a simple test case. I've found that I can get a
video to playback if it's served over http but the same file won't play if
referenced locally. So at least it's a step in the right direction!
############################
import sys, os
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtGui import QIcon
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
from PyQt5.QtMultimediaWidgets import QVideoWidget
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.player = QMediaPlayer()
# local file, fails to play:
# error code 1 - ResourceError - A media resource couldn't be
resolved.
# MediaStatus code 8 - InvalidMedia - The current media cannot be
played. The player is in the StoppedState.
p =
QMediaContent(QUrl.fromLocalFile('C:\\Users\\rob\\Downloads\\Red_Dancing.wmv'))
# Same file served using Node http-server works
p = QMediaContent(QUrl('http://localhost:8080/Red_Dancing.wmv'))
self.player.setMedia(p)
self.player.setVolume(50)
self.player.error.connect(self.error)
self.player.mediaStatusChanged.connect(self.mediaStatus)
self.player.bufferStatusChanged.connect(self.bufferStatus)
self.videoWidget = QVideoWidget();
self.player.setVideoOutput(self.videoWidget);
self.setCentralWidget(self.videoWidget)
self.videoWidget.show();
self.player.pause()
self.setGeometry(300, 300, 350, 250)
self.setWindowTitle('Video')
self.show()
def error(self, e):
print('error', e)
def mediaStatus(self, e):
print('mediaStatus', e)
if e == 6 or e == 7: self.player.play()
def bufferStatus(self, e):
print('bufferStatus', e)
def closeEvent(self, event):
self.player.stop()
self.player.setParent(None)
self.player.deleteLater()
self.player = None
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
############################
That code works with mp4 and wmv files when running over http although the
buffer time is much worse with the mp4 as is the looping.
Would really appreciate any thoughts.
Cheers,
Rob
--
Sent from: http://python.6.x6.nabble.com/PyQt-f1792048.html
More information about the PyQt
mailing list