Skip to content

Commit

Permalink
Merge pull request #528 from matematikk-mooc/aj/DIT-29-dev
Browse files Browse the repository at this point in the history
 DIT-29: Auto enable caption for Vimeo player
  • Loading branch information
madsenandreas authored May 15, 2024
2 parents 345ed13 + 5ad17de commit d3339ec
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 144 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.12.2
70 changes: 52 additions & 18 deletions src/js/3party/vimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,60 @@ export default (function() {
var iframe = document.getElementById(iframeId);
player = new Player(iframe)

//Auto enables caption for Vimeo player to bokmal by default, unless user has customized option set already.
//If bokmal is not avaiable then select the first track that is avaiable.
player.getTextTracks()
.then(function(tracks) {
var tracksHasLength = tracks.length > 0;
if (tracksHasLength) {
var userHasAlreadySelected = false;
var hasBokmal = false;

for (var trackIndex in tracks) {
var trackItem = tracks[trackIndex];

var isSelected = trackItem.mode == "showing";
if (isSelected) {
userHasAlreadySelected = true;
break;
}

player.on('play', function () {
transcript.playerPlaying();
});
player.on('pause', function () {
transcript.playerNotPlaying();
});
player.getVideoTitle().then(function (title) {
});
player.on('cuechange', function (d) {
});
player.on('cuepoint', function (d) {
});
player.on('texttrackchange', function (d) {
});
player.on('playbackratechange', function (d) {
transcript.setPlaybackRate(d.playbackRate);
});
var isBokmal = trackItem.language == "nb";
if (isBokmal) {
hasBokmal = true;
}
}

};
if (!userHasAlreadySelected) {
var trackToUse = hasBokmal ? "nb" : tracks[0].language;
player.enableTextTrack(trackToUse)
.then(function (track) {})
.catch(function (err) {
console.error(err);
});
}
}
});

player.on('play', function () {
transcript.playerPlaying();
});
player.on('pause', function () {
transcript.playerNotPlaying();
});
player.getVideoTitle().then(function (title) {
});
player.on('cuechange', function (d) {
});
player.on('cuepoint', function (d) {
});
player.on('texttrackchange', function (d) {
});
player.on('playbackratechange', function (d) {
transcript.setPlaybackRate(d.playbackRate);
});

};
var findCaptionIndexFromTimestamp = function (timeStamp) {
var start = 0;
var duration = 0;
Expand Down
Loading

0 comments on commit d3339ec

Please sign in to comment.