1
votes

I can control fine this video (play, pause) at this URL: https://www.youtube.com/watch?v=5kcdRBHM7kM

I use this code with Qt 5.7.1 using QWebEngine

QString jsToDo = "document.getElementById('movie_player').playVideo();";
webEngineView->page()->runJavaScript(jsToDo);

I would like to get a fullscreen browser so when I try using the same video with this URL: https://www.youtube.com/embed/5kcdRBHM7kM?autohide=1&autoplay=1&modestbranding=1&playerapiid=ytplayer&enablejsapi=1&hl=en

The same javascript code up here is not working to control playback, I tried multiple ID without success. Is there a way to control embed youtube video that I have no control over the element ID?

1
The simple and very obvious (to me anyways) answer is that both URLs use completely different code. The second does not have a movie_player element nor any playVideo method. If you want your code to work on the second, you'll need to figure out how this code works. - Julie Pelletier
I guess this is the problem. I tried analysing the source code at the second Url to find the mediaplayer ID without success. I am starting to wonder if it is even possible to control the media player from this Url. Merci Julie. - Astro

1 Answers

0
votes

I got it to work with this piece of javascript

QString jsToDo2 = "document.getElementById('player').children[0].pauseVideo();";
  webEngineView->page()->runJavaScript(jsToDo2);

Cheers