PDA

View Full Version : problem with custom qnetworkaccessmanager in qwebpage



januszmk
21st July 2014, 12:23
Hi. I have problem with QWebView and custom QNetworkAccessManager class.
I want to use html5 video function to watch encrypted local videos. My code:

QWebSecurityOrigin::addLocalScheme("courses");
m_view = new QWebView(this);
m_view->page()->setNetworkAccessManager(new NetworkAccessManager);
m_view->load(QUrl::fromLocalFile("index.html"));

<!DOCTYPE html>
<html>
<head> <meta
charset="utf-8" /></head>
<body>
<img src="courses://test" />
<video controls>
<source src="courses://big_buck_bunny.cmp4" type="video/mp4" />
</video>
</body>
</html>


#include "NetworkAccessManager.h"
#include "NetworkReply.h"
#include <QDebug>

NetworkAccessManager::NetworkAccessManager(QObject *parent) :
QNetworkAccessManager(parent)
{
}

QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
{
qDebug() << request.url() << request.url().scheme();
if (op != GetOperation || request.url().scheme() != "courses")
return QNetworkAccessManager::createRequest(op, request, outgoingData);
return new NetworkReply(this, request);
}


QWebView is calling my NetworkAccessManager::createRequest function only for index.html and img, for video first it's says that gstreamer cannot pause - "link", and then: Error, courses URI schema is not implemented.
Could someone tell me how can I implement custom data reading for videos in webkit?

ChrisW67
21st July 2014, 22:16
What you have done looks roughly correct to me (working from memory).

The URL might be directed to GStreamer as soon as a supported media type is seen. What happens if you omit the media type or set something that cannot be handled by the inbuilt GStreamer video support?

januszmk
22nd July 2014, 01:22
What you have done looks roughly correct to me (working from memory).

The URL might be directed to GStreamer as soon as a supported media type is seen. What happens if you omit the media type or set something that cannot be handled by the inbuilt GStreamer video support?

If I set type to random string then nothing is happening, no request, no gstreamer logs. If I ommit the media type, I get the same results as with type mp4

januszmk
25th July 2014, 16:17
I have some idea how to solve this but I am stuck with two problems now.
In QMediaPlayer there is slot

void QMediaPlayer::setMedia(const QMediaContent & media, QIODevice * stream = 0)
So I can implement my own QIODevice to read encrypted video files.
I found this article: http://daniel-albuschat.blogspot.com/2008/12/embedding-qt-widgets-into-qtwebkit.html how to create own widget in QWebView, so I created my own class videowidget:

#ifndef VIDEOWIDGET_H
#define VIDEOWIDGET_H

#include <QtMultimediaWidgets/QVideoWidget>

class VideoWidget : public QVideoWidget
{
Q_OBJECT
public:
explicit VideoWidget(QWidget *parent = 0);
VideoWidget(const VideoWidget &other);

signals:

public slots:

};
Q_DECLARE_METATYPE(VideoWidget)

#endif // VIDEOWIDGET_H


#include "VideoWidget.h"

VideoWidget::VideoWidget(QWidget *parent) :
QVideoWidget(parent)
{
.........
}

VideoWidget::VideoWidget(const VideoWidget &other)
{
}

and my main:

int main(int argc, char *argv[])
{

qRegisterMetaType<VideoWidget>();
QApplication a(argc, argv);
Creator w;
w.show();

return a.exec();
}

and html file:


<!DOCTYPE html>
<html>
<head> <meta
charset="utf-8"></head>
<body>

<object type="application/x-qt-plugin" classid="VideoWidget" name="VideoWidget" height=300 width=500></object>
</body>
</html>


Now, when my WebPage::createPlugin is called (my webpage class looks the same as in example) I am getting error "QFormBuilder was unable to create a widget of the class 'VideoWidget'." and instance of my class VideoWidget is not created. Any idea how to make this work?
The second problem is that QVideoWidget doesn't have such controls to play, pause as in webkit player, is there a easy way to create that controls like in <video> webkit player?

thanks in advance