<div dir="ltr"><div>Hello,</div><div>I'm trying to show a Youtube player inside a QML scene. I therefore replicated the available example in Qt and I'm loading this html code into a QML WebView:</div><div><br></div>
<html><br> <head><br> <title>-1</title><br> <meta name="viewport"<br> content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/><br>
</head><br> <body bgcolor="black" marginwidth="0" marginheight="0"><br> <!-- The <iframe> (and video player) will replace this <div> tag. --><br> <div id="player"></div><br>
<script><br> function getVideoId() {<br> return window.location.href.slice(window.location.href.indexOf('?') + 1);<br> }<br><br> // This code loads the IFrame Player API code asynchronously.<br>
var tag = document.createElement('script');<br> tag.src = "<a href="https://www.youtube.com/iframe_api">https://www.youtube.com/iframe_api</a>";<br> var firstScriptTag = document.getElementsByTagName('script')[0];<br>
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);<br><br> // This function creates an <iframe> (and YouTube player)<br> // after the API code downloads.<br> var player;<br> function onYouTubeIframeAPIReady() {<br>
player = new YT.Player('player', {<br> playerVars: { 'html5': 1, 'iv_load_policy': 3 },<br> frameborder: '0',<br> height: '100%',<br> width: '100%',<br>
videoId: "GgDDXXeYJeI",<br> events: {<br> 'onReady': onPlayerReady,<br> 'onStateChange': onPlayerStateChange,<br> 'onError': onPlayerError<br>
}<br> });<br> }<br><br> // The API will call this function when the video player is ready.<br> function onPlayerReady(event) {<br> document.title = "onPlayerReady";<br>
console.log("onPlayerReady callback.");<br> navigator.qt.postMessage("onPlayerReady callback.");<br> }<br><br><br> // The API calls this function when the player's state changes.<br>
function onPlayerStateChange(event) {<br> document.title = "onPlayerStateChange";<br> //navigator.qt.postMessage("onPlayerStateChange");<br> if (event.data == YT.PlayerState.PLAYING)<br>
console.log("Playing state received.");<br> else if (YT.PlayerState.ENDED == event.data)<br> console.log("Ended state received.");<br> else if (YT.PlayerState.PAUSED == event.data)<br>
console.log("Paused state received.");<br> else if (YT.PlayerState.BUFFERING == event.data)<br> console.log("Buffering state received.");<br> else if (YT.PlayerState.CUED == event.data)<br>
console.log("Cued state received.");<br> else if (event.data == -1)<br> console.log("Unstarted state received.");<br> else<br> console.log("Unknown event.data " + event.data + ".");<br>
}<br><br> function onPlayerError() {<br> document.title = "Error occurred!"<br> navigator.qt.postMessage(event.data);<br> }<br> </script><br> </body><br></html><div>
<br></div><div>What seems to happen is that no callback is invoked at all. No onPlayerReady, no onPlayerStateChange and no onPlayerError. I tried both to post a message and set the title. If I load the same html into Chromium or Firefox I get all my callbacks.</div>
<div>Any idea why or what can I do to add the player and get callbacks?</div><div><br></div><div>I also tried to use the getPlayerState() method of the player from QML, but that seemed to hang.</div><div><br></div><div>Any advice?</div>
<div>Thanks.</div><div><br></div><div>Luca</div></div>