Open HQYang1979 opened 3 years ago
Hm, the console output is not really helpful here. I rarely encounter problems with the Youtube player, in many cases an Anki restart helped. Does no video work? What is displayed on opening the video, any message?
No idea why, it suddenly works now! It's bugged me for three days. Thank you very much though.
You're really doing a great job.
it happens again. I can import the video, that means connection is fine, but just cannot play it.
Hi, anything in the console if that happens?
I can import the video, that means connection is fine
To create the video note, you don't have to have a working internet connection, only to actually watch.
There's nothing shown on the console...sometime it works sometime it wont. said it is youtube api problem as in the above screenshot.
@fonol I have a similar bug to @HQYang1979 most of the time it displays a notification of the YouTube video's title but sits there with a blank screen. Rarely do I get a the YouTube API/internet connection warning.
Then some times after repeatedly trying it plays the video.
I put some extra logging into the python backend source I couldn't see any issues, so I thought it was the javascript. So I used the Anki add-on AnkiWebView Inspector (31746032) to open up a JS console for the webview on the add screen whilst opening a video note.
From the console I believe that the issue is caused by trying to use the YT Player before it has time to download and initialise.
as you can see later I was able to reference YT and YT.Player meaning that they had loaded eventually.
The YT Player API reference shows how to asynchronously load the API code it also mentions a callback function called onYouTubeIframeAPIReady
which is called after the YT API has downloaded.
Any web page that uses the IFrame API must also implement the following JavaScript function:
onYouTubeIframeAPIReady – The API will call this function when the page has finished downloading the JavaScript for the player API, which enables you to then use the API on your page. Thus, this function might create the player objects that you want to display when the page loads.
example from the page
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
if you wish you can then create the event callbacks.
onPlayerReady for when the video is ready in the player. onStateChange
So I wonder if moving some of the code into these callbacks and a few changes would resolve this issue?
Thanks, it really sounds like it could be the issue. Although I wonder, if you open the Add dialog, and open a note in the reader, the API should have had plenty of time to load by then. Maybe the problem only occurs if you open a Youtube note with something like ctrl+o, where the Add dialog was not previously open, so that there is little time between the script loading and opening the note in the reader? Anyway, making sure that the async loading has finished makes sense and I'll definitely include it with the next update.
where the Add dialog was not previously open, so that there is little time between the script loading and opening the note in the reader?
yes I think that's what is happening
Add dialog, and open a note in the reader, the API should have had plenty of time to load by then.
Yes, that seems to be the case. I do occasionally get a YouTube page saying something went wrong.. not sure what that is at the moment.
I was opening from the queue screen so the browser screen had not loaded before. Different workflows and different internet speeds would explain why it isn't an issue for everyone.
Anyway, making sure that the async loading has finished makes sense and I'll definitely include it with the next update.
I think that's probably the right thing to do long-term.
Is it also possible to use caching and Etags saving on downloading API every time?
I do occasionally get a YouTube page saying something went wrong.. not sure what that is at the moment.
Not seen the YouTube error screen mentioned since.
@OQHan
There are several ways to open video notes which are you using?
@OQHan that's a bummer. How often does that still happen, and if it happens, still nothing suspicious in the console?
@HQYang1979 Have you tried the new update? Did it solve the issue?
I am sure my connection is fine though. this is the console message, but it seems not related.