mirror of
https://github.com/gosticks/PiPer.git
synced 2026-07-01 13:50:01 +00:00
Fixed high CPU usage bug
Fixed high CPU usage bug that was apparent during adverts in YouTube; occured as a result of working around Safari bug where 'removeCue' doesn't immediately remove captions
This commit is contained in:
Binary file not shown.
@@ -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 = '';
|
||||
|
||||
/**
|
||||
@@ -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';
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -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, ''));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.2.5</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>150</string>
|
||||
<string>151</string>
|
||||
<key>Developer Identifier</key>
|
||||
<string>BQ6Q24MF9X</string>
|
||||
<key>URL</key>
|
||||
|
||||
Reference in New Issue
Block a user