Unable to play ogg files inside a qtwebview, rest of media files ok
sombra2eternity last edited by
I have been reading so many post about this but was unable to find a solution, it seems to me more than a bug, and I would like to read your opinion on this matter.
I have ubuntu 12.04 and synaptic tells me my Qt version is -> libqtcore4 = 4:4.8.1
- Use the webkit audio support to play files
- Feed it to the player using a custom NetworkAccessManager recognising files with a url header
from PyQt4 import QtGui, QtCore, QtWebKit, QtNetwork
from PyQt4.QtCore import QUrl
def init(self, parent):
def createRequest(self,operation,request,outgoingData): url = unicode(request.url().toString()) if url.startswith('http://mycustomprotocol') : localFile = url[24:]; print localFile request.setUrl(QUrl.fromLocalFile(localFile)) reply = QtNetwork.QNetworkAccessManager.createRequest(self,operation,request,outgoingData) self.emit(QtCore.SIGNAL('networkRequestCreated(QNetworkReply*)'),reply) #print 'createRequest',url,operation #self.connect(reply, QtCore.SIGNAL('downloadProgress(qint64, qint64)'), self.foo) return reply def foo(self, *args): print args
# Ventana del programa
self.tabWidget = QtGui.QTabWidget(self) self.setCentralWidget(self.tabWidget) self.webview = QtWebKit.QWebView() self.n = NetworkAccessManager(self); self.webview.page().setNetworkAccessManager(self.n) self.tabWidget.setCurrentIndex(self.tabWidget.addTab(self.webview,'loading...')) #self.webview.setUrl(QUrl.fromLocalFile("index.html")) self.webview.setUrl(QUrl.fromLocalFile("/home/marcos/Descargas/examp/index.html"))
app = QtGui.QApplication(sys.argv)
browser = Browser()
if name == 'main':
<div><audio src='http://mycustomprotocol/1.mp3' controls=true/></div>
<div><audio src='http://mycustomprotocol/1.ogg' controls=true/></div>
<div><audio src='http://mycustomprotocol/1.wav' controls=true/></div>
Please, note that in "player.py" you need to change the path in "self.webview.setUrl(QUrl.fromLocalFile("/home/marcos/Descargas/examp/index.html"))" because I was unable to load it from a relative path. In the "index.html" are listed various audio files that you will need to suply in order the NetworkAccessManager to detect them -> [1.ogg,1.mp3,1.wav], there are examples of media files all around internet like http://en.wikipedia.org/wiki/File:Example.ogg
Ok, when the test is set you will find that mp3 and wav file loads and cand be played, bot ogg not too much. NetworkAccessManager is writed to find a spetial header in the url and respond with a local file. Firstly I though it was a bad header or mimetypes and override it in the NetworkAccessManager class but with not too much luck. If you load html5test inside a webview you found that it have full support for audio files (almost in my case), and even better, if I load the wikipedia example in the URL im able to play the ogg example file. So for sure the webview have capacity to play this kind of files. I can see twice the petition of the ogg file if I print the NetworkAccessManager requests and look like the html5 audio tag checking the ogg exists but not founding it. All the other media files make an alone petition.
Im quite stuck, please give me some hints.