anki-search-inside-add-card icon indicating copy to clipboard operation
anki-search-inside-add-card copied to clipboard

Cannot Open Youtube Video

Open HQYang1979 opened this issue 3 years ago • 13 comments

image

I am sure my connection is fine though. image this is the console message, but it seems not related.

HQYang1979 avatar Feb 25 '21 08:02 HQYang1979

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?

fonol avatar Feb 25 '21 08:02 fonol

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.

HQYang1979 avatar Feb 25 '21 09:02 HQYang1979

image

it happens again. I can import the video, that means connection is fine, but just cannot play it.

HQYang1979 avatar Feb 25 '21 11:02 HQYang1979

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.

fonol avatar Feb 28 '21 08:02 fonol

There's nothing shown on the console...sometime it works sometime it wont. said it is youtube api problem as in the above screenshot.

HQYang1979 avatar Mar 01 '21 10:03 HQYang1979

@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.

Screenshot 2021-03-15 at 20 02 41

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?

andrewcrook avatar Mar 16 '21 10:03 andrewcrook

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.

fonol avatar Mar 17 '21 06:03 fonol

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?

andrewcrook avatar Mar 17 '21 14:03 andrewcrook

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.

andrewcrook avatar Mar 19 '21 10:03 andrewcrook

image

OQHan avatar Mar 25 '21 08:03 OQHan

@OQHan

There are several ways to open video notes which are you using?

andrewcrook avatar Mar 25 '21 10:03 andrewcrook

@OQHan that's a bummer. How often does that still happen, and if it happens, still nothing suspicious in the console?

fonol avatar Mar 26 '21 06:03 fonol

@HQYang1979 Have you tried the new update? Did it solve the issue?

OcileCollection avatar Aug 15 '22 18:08 OcileCollection