Skip to content

Player does not work when captions are unavailables on Youtube #554

Closed

Description

@DuaelFr

I've been struggling for quite some time with what seemed to be a random bug.

As you can see on this page the video player is loaded but no controls are available whereas on this other page it works perfectly.
Without errors in the browser console I had to dig a lot to understand that in the first case, captions are not available at all (not even auto-generated ones so the button is disabled on the Youtube player), while in the second case auto-generated captions are available (on Youtube only, AblePlayer doesn't seem to support them for now).

I hope this gives you enough context to find a fix!
Feel free to ask me if you need more info.

Activity

  1. xerc commented on Dec 10, 2022

    @xerc
    Contributor

    remove data-hide-controls="false" and add playsinline
    btw/ there is no need for ="true" @ data-youtube-nocookie

  2. DuaelFr commented on Dec 12, 2022

    @DuaelFr
    ContributorAuthor

    Thank you @xerc for your suggestions but it does not fix the issue.

  3. xerc commented on Dec 12, 2022

    @xerc
    Contributor

    caption-functions do not behave "normal" with YT ; #562

  4. drumwhacker commented on May 16, 2023

    @drumwhacker

    Having this issue as well. Did you decide not to use the player?

  5. DuaelFr commented on May 17, 2023

    @DuaelFr
    ContributorAuthor

    Sadly we had to remove AblePlayer for Youtube videos because of this issue. We kept it for self hosted ones and for audio content though.

  6. drumwhacker commented on May 17, 2023

    @drumwhacker
  7. terrill commented on May 17, 2023

    @terrill
    Member

    Hi All. Sorry for my slow response to this and other issues. Things have been a bit crazy at the University of Washington and maintaining Able Player has taken a back seat to other priorities. I'm planning to shift my focus back to Able Player starting next week (Monday May 22). Stay tuned for updates...

  8. drumwhacker commented on May 17, 2023

    @drumwhacker
  9. terrill commented on Jun 13, 2023

    @terrill
    Member

    Can someone provide a URL to a page that demonstrates this problem? I'm unable to replicate it. From my tests, the Able Player chrome is built without error for YouTube videos that have no captions as well as those that have machine-generated captions only. Also, be sure you're using the latest version of Able Player from the develop branch.

  10. drumwhacker commented on Jun 15, 2023

    @drumwhacker

    Hi Terrill, You can view what happens for me here:
    https://riosalado.coursearc.com/content/toolbox/cg-test-blocks/ableplayer-v1-set-up-no-caption-track/

    We have a home-rolled script that sets up ableplayer within a page multiple times based on class cues found. Currently using 4.4.67, however, my tests use 4.5, which set up with the same problem as 4.4.67 (no control bar, sometimes autoplays).

  11. stuprice commented on Jun 19, 2023

    @stuprice

    Hi

    I'm suffering from this problem too and the link @drumwhacker provided above shows the exact same behaviour as I see. I've compared the latest dev build to the release version and there are no changes in the area where I think the problem lies.

    I have tried to debug the problem and here's what I think the issue is.

    In AblePlayer.prototype.getYouTubeCaptionTracks() it determines there are no options for 'captions' or 'tracklist' so it's adds an event handler like this:

    // no tracks were found, probably because the captions module hasn't loaded // play video briefly (required in order to load the captions module) // and after the apiChange event is triggered, try again to retreive tracks this.youTubePlayer.addEventListener('onApiChange',function(x)

    However, as there are no captions in the video, the captions module never loads so onApiChange never gets raised. This means the video plays, doesn't get paused and deferred.resolve(); never gets called.

    The impact is the chain of If statements in AblePlayer.prototype.recreatePlayer = function () stops at thisObj.getTracks().then(function() and doesn't cascade down to create the player controls (as well as other stuff).

    It seems we need to know that the event handler has been added and the video has started playing but the apiOnChange event hasn't fired and is never going to. Alternatively if the captions state is unknown for a given period of time just give up and resolve the promise.

    I hope this helps and makes sense.

  12. drumwhacker commented on Jun 19, 2023

    @drumwhacker
  13. drumwhacker commented on Jun 19, 2023

    @drumwhacker

    If you hard-refresh the test page I shared, you can see in the code where I have set up in the area you pointed out. The timeout is arbitrary, probably could be a lot short like 500 or 300.

  14. stuprice commented on Jun 20, 2023

    @stuprice

    Hi

    I can see your page no longer autoplays the video but it still doesn't show the player controls so we're 50% of the way there.

    However I can't see any of the changes you've made to make this happen? Can you give me a pointer?

    I'll try and have a go today to fix the ableplayer source when captions are missing.

    Cheers

    Stu

  15. 21 remaining items

  16. joedolson commented on Jul 24, 2025

    @joedolson
    Member

    @drumwhacker I added a PR with what I understand you to be doing linked to this issue. Let me know if I've understood correctly.

    I did change the call to .stopVideo() to .pauseVideo(), as stopVideo cancels loading.

    What I'm finding is that it works part of the time; it's just not 100% dependable for me.

  17. joedolson commented on Jul 24, 2025

    @joedolson
    Member

    OK. Fixed the PR; it's based against the develop branch.

  18. joedolson commented on Aug 10, 2025

    @joedolson
    Member

    I'm not managing to get this working reliably, and it's a relatively low priority scenario (videos with no captions are not really the target need for Able Player), so I'm going to move it to the next milestone.

  19. modified the milestones: 4.7, 4.8 on Aug 10, 2025
  20. drumwhacker commented on Aug 11, 2025

    @drumwhacker
  21. joedolson commented on Aug 12, 2025

    @joedolson
    Member

    I found another way to possibly solve this. There's an undocumented path to use setOption to set a caption file, and if there are no captions available in that language, it will enable the auto captions generated by YouTube.

    This does two things: 1) it would make craptions available if no captions are provided and 2) might mean that this error with uncaptioned videos doesn't happen.

    I did some tests, and it does work in a basic scenario, but there's a fair amount more to do to make it work properly.

    However, to test it at a basic level, you can add

    if (typeof thisObj.youTubePlayer.setOption === 'function') {
    	thisObj.youTubePlayer.setOption('captions', 'track', {languageCode: 'en'})
    }
    

    in the else block if there are no ytTrack in getYouTubeCaptionTracks().

    Also need to set thisObj.usingYouTubeCaptions = false; and thisObj.hasCaptions = false; to true in that condition.

    I'm not going to explore this further until I start prepping 4.8, but this might be an alternate path.

  22. joedolson commented on Dec 31, 2025

    @joedolson
    Member

    I was just testing this, and in my testing today, I'm finding that this issue isn't occurring anymore - the captions module is getting loaded, and the controls execute. I could use a second confirmation on this, but I'm pretty sure this has changed.

    In my test, I was able to get confirmation that the video I tested with had no captions on YouTube, but the controls rendered as expected. I did this both with the current develop branch and the 4.7 release.

  23. cscottjames commented on Dec 31, 2025

    @cscottjames

    Sadly, I'm still seeing this on develop and 4.7. I'm testing using a YouTube video with no words whatsoever. Examples are easy to find, like this for example https://www.youtube.com/watch?v=1x28RF72xZc

  24. joedolson commented on Dec 31, 2025

    @joedolson
    Member

    Must be that they resolved an issue with auto captions that I was finding previously, but no text is a different issue. Thanks for the example; I'll keep working. Unfortunately, this probably means that the alternate fix I'd come up with is irrelevant for this issue, as I doubt it would work in this scenario. But I'll find out.

  25. joedolson commented on Dec 31, 2025

    @joedolson
    Member

    I'm thinking that the most stable and consistent solution is to add a flag that indicates that a video doesn't have captions, and use that to disable the entire captions fetch process. Something like data-youtube-nocaptions. It's not automatic, but given that as things are right now, there cannot be any Able Players out there that are functional in this scenario, I don't think that's a major concern.

    While the timeout solution works, I'm concerned that it will have the side effect that a delay > 1s in loading the captions module will result in captions being disabled. I'm not sure how big a problem that is, however, and haven't been able to trigger it. I used a test case with 23 caption files, which wasn't a problem.

    For now, I'm going to commit the setTimeout solution to develop to try and get further testing, but I'm going to leave this open.

    If only the YouTube iFrame API had a way to differentiate between "this module has not loaded yet" and "this module will not load"...

  26. cscottjames commented on Jan 2, 2026

    @cscottjames

    I can see how those might be two separate issues (1 - not finding captions that exist; 2 - not finding any captions because they don't exist at all).

    It would be nice if there was a way to automatically detect the absence of captions, but if that isn't feasible then a flag or attribute would suffice.

  27. joedolson commented on Jan 10, 2026

    @joedolson
    Member

    This seems to be working; I'm going to ship with it this way, and if I need to do a follow up, I'll do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions