Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Disable sound in QWebPage
Forum Updated to NodeBB v4.3 + New Features

Disable sound in QWebPage

Scheduled Pinned Locked Moved Qt WebKit
2 Posts 2 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alexandros
    wrote on last edited by
    #1

    Is it possible to disable sound in QWebPage ? Till now I've managed to completely disable javascript pop-ups etc using this code:

    @class CustomWebPage : public QWebPage {
    protected:
    virtual QString chooseFile(QWebFrame , const QString&) { return QString(); }
    virtual void javaScriptAlert (QWebFrame
    , const QString &) {}
    virtual bool javaScriptConfirm(QWebFrame *, const QString &) { return false; }
    virtual bool javaScriptPrompt(QWebFrame *, const QString &, const QString &, QString *) { return false; }
    };@

    I also tried muting any <audio> and <video>, but unsuccessfully:

    @QWebElement bodyElem = webPage->mainFrame()->documentElement().findFirst("body");

    bodyElem.evaluateJavaScript("var mute=function(tag){"\
                                             "    var elems = document.getElementsByTagName(tag);"\
                                             "    for(var i = 0; i < elems.length; i++){"\
                                             "        elems[i].muted=true;" \
                                             "    }    "\
                                             "}"\
                                             "mute(\"video\");"\
                                             "mute(\"audio\");"\
                                             );@
    

    While the above code works here, for example: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_audio_muted

    But this was just a workaround. I would like, if possible, to mute the whole QWebPage.

    1 Reply Last reply
    1
    • N Offline
      N Offline
      navisrob
      wrote on last edited by
      #2

      Thanks, your js code works, but only after some time (when page already loaded)

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved