Results 1 to 4 of 4

Thread: problem with custom qnetworkaccessmanager in qwebpage

  1. #1
    Join Date
    Jul 2011
    Location
    Kraków / Poland
    Posts
    32
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default problem with custom qnetworkaccessmanager in qwebpage

    Hi. I have problem with QWebView and custom QNetworkAccessManager class.
    I want to use html5 video function to watch encrypted local videos. My code:
    Qt Code:
    1. QWebSecurityOrigin::addLocalScheme("courses");
    2. m_view = new QWebView(this);
    3. m_view->page()->setNetworkAccessManager(new NetworkAccessManager);
    4. m_view->load(QUrl::fromLocalFile("index.html"));
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. <!DOCTYPE html>
    2. <html>
    3. <head> <meta
    4. charset="utf-8" /></head>
    5. <body>
    6. <img src="courses://test" />
    7. <video controls>
    8. <source src="courses://big_buck_bunny.cmp4" type="video/mp4" />
    9. </video>
    10. </body>
    11. </html>
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "NetworkAccessManager.h"
    2. #include "NetworkReply.h"
    3. #include <QDebug>
    4.  
    5. NetworkAccessManager::NetworkAccessManager(QObject *parent) :
    6. QNetworkAccessManager(parent)
    7. {
    8. }
    9.  
    10. QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
    11. {
    12. qDebug() << request.url() << request.url().scheme();
    13. if (op != GetOperation || request.url().scheme() != "courses")
    14. return QNetworkAccessManager::createRequest(op, request, outgoingData);
    15. return new NetworkReply(this, request);
    16. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: problem with custom qnetworkaccessmanager in qwebpage

    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?

  3. #3
    Join Date
    Jul 2011
    Location
    Kraków / Poland
    Posts
    32
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: problem with custom qnetworkaccessmanager in qwebpage

    Quote Originally Posted by ChrisW67 View Post
    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

  4. #4
    Join Date
    Jul 2011
    Location
    Kraków / Poland
    Posts
    32
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: problem with custom qnetworkaccessmanager in qwebpage

    I have some idea how to solve this but I am stuck with two problems now.
    In QMediaPlayer there is slot
    Qt Code:
    1. void QMediaPlayer::setMedia(const QMediaContent & media, QIODevice * stream = 0)
    To copy to clipboard, switch view to plain text mode 
    So I can implement my own QIODevice to read encrypted video files.
    I found this article: http://daniel-albuschat.blogspot.com...-qtwebkit.html how to create own widget in QWebView, so I created my own class videowidget:
    Qt Code:
    1. #ifndef VIDEOWIDGET_H
    2. #define VIDEOWIDGET_H
    3.  
    4. #include <QtMultimediaWidgets/QVideoWidget>
    5.  
    6. class VideoWidget : public QVideoWidget
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit VideoWidget(QWidget *parent = 0);
    11. VideoWidget(const VideoWidget &other);
    12.  
    13. signals:
    14.  
    15. public slots:
    16.  
    17. };
    18. Q_DECLARE_METATYPE(VideoWidget)
    19.  
    20. #endif // VIDEOWIDGET_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "VideoWidget.h"
    2.  
    3. VideoWidget::VideoWidget(QWidget *parent) :
    4. QVideoWidget(parent)
    5. {
    6. .........
    7. }
    8.  
    9. VideoWidget::VideoWidget(const VideoWidget &other)
    10. {
    11. }
    To copy to clipboard, switch view to plain text mode 
    and my main:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3.  
    4. qRegisterMetaType<VideoWidget>();
    5. QApplication a(argc, argv);
    6. Creator w;
    7. w.show();
    8.  
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 
    and html file:
    Qt Code:
    1. <!DOCTYPE html>
    2. <html>
    3. <head> <meta
    4. charset="utf-8"></head>
    5. <body>
    6.  
    7. <object type="application/x-qt-plugin" classid="VideoWidget" name="VideoWidget" height=300 width=500></object>
    8. </body>
    9. </html>
    To copy to clipboard, switch view to plain text mode 

    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

Similar Threads

  1. Replies: 2
    Last Post: 18th January 2012, 15:01
  2. Custom qNetworkAccessManager for WebView
    By xeento in forum Qt Programming
    Replies: 2
    Last Post: 25th May 2010, 04:22
  3. Unwanted downloads with QWebPage/QWebPage
    By ouekah in forum Newbie
    Replies: 6
    Last Post: 11th May 2010, 22:48
  4. problem with window.location in QWebPage
    By speedy_gonzales in forum Qt Webkit
    Replies: 0
    Last Post: 24th February 2010, 05:40
  5. Replies: 2
    Last Post: 9th January 2010, 02:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.