Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QWebView - play/pause video programmatically?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QWebView - play/pause video programmatically?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.4k Views 1 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.
  • M Offline
    M Offline
    maximus
    wrote on 20 Jan 2015, 21:39 last edited by
    #1

    I am trying to control the playback of YouTube video that is played inside a QWebView :
    "See use-case picture":https://www.dropbox.com/s/a02hw55ngzvuaie/useCaseYoutube.png?dl=0

    The player can be controller with the "YouTube Javascript API":https://developers.google.com/youtube/js_api_reference

    Problem is that most of theses examples use embedded video. I use the YouTube website directly and not embedded video.

    What I tried so far (no success yet):

    @void WebBrowser::pauseVideo() {

    qDebug() << "WebBrowser::pauseVideo()";
    
    QString jsValue =  "$('#movie_player').pauseVideo();";
    ui->webView->page()->mainFrame()->evaluateJavaScript(jsValue);
    ui->webView->page()->mainFrame()->documentElement().evaluateJavaScript(jsValue);
    
    
    jsValue = "$('#movie_player').get(0).pauseVideo();";
    ui->webView->page()->mainFrame()->evaluateJavaScript(jsValue);
    ui->webView->page()->mainFrame()->documentElement().evaluateJavaScript(jsValue);
    

    }
    void WebBrowser::playVideo() {

    qDebug() << "WebBrowser::playVideo()";
    
    QString jsValue = "$('#movie_player').playVideo();";
    ui->webView->page()->mainFrame()->evaluateJavaScript(jsValue);
    ui->webView->page()->mainFrame()->documentElement().evaluateJavaScript(jsValue);
    
    jsValue = "$('#movie_player').get(0).playVideo();";
    ui->webView->page()->mainFrame()->evaluateJavaScript(jsValue);
    ui->webView->page()->mainFrame()->documentElement().evaluateJavaScript(jsValue);
    

    }
    @

    Any help is welcome, I'm sure it can be done
    Inside youtube source code of a page I can see " "enablejsapi": 1," but maybe i'm not using the right playerID?


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximus
      wrote on 20 Jan 2015, 22:07 last edited by
      #2

      Solved!

      Youtube page doesn't use jquery ;)

      @//-----------------------------------------------------------------
      void WebBrowser::playVideo() {

      qDebug() << "WebBrowser::playVideo()";
      
      QString jsValue = "document.getElementById('movie_player').playVideo();";
      ui->webView->page()->mainFrame()->evaluateJavaScript(jsValue);
      

      }
      @


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply
      0

      1/2

      20 Jan 2015, 21:39

      • Login

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