Skip to content

Commit

Permalink
Merge pull request #61 from amarcu5/develop
Browse files Browse the repository at this point in the history
v0.2.5+hotfix.1
  • Loading branch information
amarcu5 authored Sep 9, 2018
2 parents 8145d00 + 1cc5562 commit 0a7cc74
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Binary file modified out/PiPer.safariextz
Binary file not shown.
11 changes: 8 additions & 3 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ let /** ?Element */ button = null;
let /** ?PiperResource */ currentResource = null;
let /** ?TextTrack */ track = null;
let /** boolean */ showingCaptions = false;
let /** boolean */ showingEmptyCaption = false;
let /** string */ lastUnprocessedCaption = '';

/**
Expand Down Expand Up @@ -136,6 +137,7 @@ const prepareCaptions = function(video) {
// Otherwise create new caption track
log('Caption track created');
track = video.addTextTrack('captions', TRACK_ID, 'en');
track.mode = 'showing';
};

/**
Expand Down Expand Up @@ -166,11 +168,12 @@ const videoPresentationModeChanged = function(event) {
* @param {boolean} workaround - apply Safari bug workaround
*/
const removeCaptions = function(video, workaround = true) {
track.mode = 'showing';
while (track.activeCues.length) track.removeCue(track.activeCues[0]);

// Workaround Safari bug; 'removeCue' doesn't immediately remove captions shown in Picture in Picture mode
if (workaround) track.addCue(new VTTCue(video.currentTime, video.currentTime + 60, ''));
if (workaround && video) {
track.addCue(new VTTCue(video.currentTime, video.currentTime + 60, ''));
}
};

/**
Expand All @@ -184,8 +187,9 @@ const processCaptions = function() {

// Remove Picture in Picture mode captions and show native captions if no longer showing captions or encountered an error
if (!showingCaptions || !captionElement) {
removeCaptions(video);
removeCaptions(video, !showingEmptyCaption);
if (captionElement) captionElement.style.visibility = '';
showingEmptyCaption = true;
return;
}

Expand Down Expand Up @@ -225,6 +229,7 @@ const processCaptions = function() {
caption = caption.trim();
log('Showing caption "' + caption + '"');
track.addCue(new VTTCue(video.currentTime, video.currentTime + 60, caption));
showingEmptyCaption = false;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion update.plist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<key>CFBundleShortVersionString</key>
<string>0.2.5</string>
<key>CFBundleVersion</key>
<string>149</string>
<string>151</string>
<key>Developer Identifier</key>
<string>BQ6Q24MF9X</string>
<key>URL</key>
Expand Down

0 comments on commit 0a7cc74

Please sign in to comment.