Unable to play ogg files inside a qtwebview, rest of media files ok

  • 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
    Im using it with python to make a own media juckebox, I think I could use QML or something similar to create the interfaces, but I dont feel yet too mucho confortable with python or Qt either so I tried to get near HTML/javascript as much as I could. The app works following the next design:

    • Use the webkit audio support to play files
    • Feed it to the player using a custom NetworkAccessManager recognising files with a url header

    @#!/usr/bin/env python

    import sys,gtk,webkit,os,json,re,base64,urllib2,sqlite3,math,time,Queue,mimetypes,subprocess
    from PyQt4 import QtGui, QtCore, QtWebKit, QtNetwork
    from PyQt4.QtCore import QUrl

    class NetworkAccessManager(QtNetwork.QNetworkAccessManager):
    def init(self, parent):
    QtNetwork.QNetworkAccessManager.init(self, parent)

    def createRequest(self,operation,request,outgoingData):
        url = unicode(request.url().toString())
        if url.startswith('http://mycustomprotocol') :
            localFile = url[24:];
            print localFile
        reply = QtNetwork.QNetworkAccessManager.createRequest(self,operation,request,outgoingData)
        #print 'createRequest',url,operation
        #self.connect(reply, QtCore.SIGNAL('downloadProgress(qint64, qint64)'), self.foo)
        return reply
    def foo(self, *args):
        print args

    class Browser(QtGui.QMainWindow):
    # Ventana del programa
    def init(self):

        self.tabWidget = QtGui.QTabWidget(self)
        self.webview = QtWebKit.QWebView()
        self.n = NetworkAccessManager(self);

    def main():
    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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.