I am trying to write a program in C++ and wxWidgets that accesses YouTube and start the video with JavaScript.
It uses the YouTube JavaScript API, documentation for which is found here.
I wrote the following piece of code to play ‘O, Canada’, specifically the one here.
wxWebView *webview = wxWebView::New(this, wxID_ANY, "http://www.youtube.com/watch?v=zwDvF0NtgdU");
webview->RunScript("function onYouTubePlayerReady(playerId) {document.getElementById('watch-player').playVideo();}");
Running the above code fails to fulfill its intended purpose, giving me the following error and a crash:
....\src\msw\wxwebview_ie.cpp(762): "assert "document" failed in wxWebViewIE::GetDocument().
I know that my code successfully LOADS the page, but running the JavaScript (the RunScript()
function) seems to result in the error.
I am using wxWidgets 2.9.3 on Windows.
The problem is actually because I call the JavaScript too early, before the page is loaded. If I call it a bit later, it works.