Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed subtitles styling in firefox. #5737

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/components/subtitlesettings/subtitlesettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import template from './subtitlesettings.template.html';

function getSubtitleAppearanceObject(context) {
return {
subtitleStyling: context.querySelector('#selectSubtitleStyling').value,
venkat-karasani marked this conversation as resolved.
Show resolved Hide resolved
textSize: context.querySelector('#selectTextSize').value,
textWeight: context.querySelector('#selectTextWeight').value,
dropShadow: context.querySelector('#selectDropShadow').value,
Expand All @@ -51,6 +52,8 @@ function loadForm(context, user, userSettings, appearanceSettings, apiClient) {

context.querySelector('#selectSubtitlePlaybackMode').dispatchEvent(new CustomEvent('change', {}));

context.querySelector('#selectSubtitleStyling').value = appearanceSettings.subtitleStyling || 'Auto';
context.querySelector('#selectSubtitleStyling').dispatchEvent(new CustomEvent('change', {}));
context.querySelector('#selectTextSize').value = appearanceSettings.textSize || '';
context.querySelector('#selectTextWeight').value = appearanceSettings.textWeight || 'normal';
context.querySelector('#selectDropShadow').value = appearanceSettings.dropShadow || '';
Expand Down Expand Up @@ -117,6 +120,16 @@ function onSubtitleModeChange(e) {
view.querySelector('.subtitles' + this.value + 'Help').classList.remove('hide');
}

function onSubtitleStyleChange(e) {
const view = dom.parentWithClass(e.target, 'subtitlesettings');

const subtitleStylingHelperElements = view.querySelectorAll('.subtitleStylingHelp');
subtitleStylingHelperElements.forEach((elem)=>{
elem.classList.add('hide');
});
view.querySelector(`.subtitleStyling${this.value}Help`).classList.remove('hide');
}

function onSubtitleBurnInChange(e) {
const view = dom.parentWithClass(e.target, 'subtitlesettings');
const fieldRenderPgs = view.querySelector('.fldRenderPgs');
Expand Down Expand Up @@ -180,6 +193,7 @@ function embed(options, self) {
options.element.querySelector('form').addEventListener('submit', self.onSubmit.bind(self));

options.element.querySelector('#selectSubtitlePlaybackMode').addEventListener('change', onSubtitleModeChange);
options.element.querySelector('#selectSubtitleStyling').addEventListener('change', onSubtitleStyleChange);
options.element.querySelector('#selectSubtitleBurnIn').addEventListener('change', onSubtitleBurnInChange);
options.element.querySelector('#selectTextSize').addEventListener('change', onAppearanceFieldChange);
options.element.querySelector('#selectTextWeight').addEventListener('change', onAppearanceFieldChange);
Expand Down
11 changes: 11 additions & 0 deletions src/components/subtitlesettings/subtitlesettings.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ <h2 class="sectionTitle">
<div class="fieldDescription">${SubtitleAppearanceSettingsAlsoPassedToCastDevices}</div>
</div>

<div class="selectContainer">
<select is="emby-select" id="selectSubtitleStyling" label="${LabelSubtitleStyling}">
<option value="Auto">${Auto}</option>
<option value="Custom">${Custom}</option>
<option value="Native">${Native}</option>
</select>
<div class="fieldDescription subtitleStylingAutoHelp subtitleStylingHelp hide">${AutoSubtitleStylingHelp}</div>
<div class="fieldDescription subtitleStylingCustomHelp subtitleStylingHelp hide">${CustomSubtitleStylingHelp}</div>
<div class="fieldDescription subtitleStylingNativeHelp subtitleStylingHelp hide">${NativeSubtitleStylingHelp}</div>
</div>

<div class="selectContainer">
<select is="emby-select" id="selectTextSize" label="${LabelTextSize}">
<option value="smaller">${Smaller}</option>
Expand Down
92 changes: 52 additions & 40 deletions src/plugins/htmlVideoPlayer/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1349,31 +1349,44 @@ export class HtmlVideoPlayer {
/**
* @private
*/
requiresCustomSubtitlesElement() {
// after a system update, ps4 isn't showing anything when creating a track element dynamically
// going to have to do it ourselves
if (browser.ps4) {
return true;
}
requiresCustomSubtitlesElement(userSettings) {
const subtitleAppearance = userSettings.getSubtitleAppearanceSettings();
switch (subtitleAppearance.subtitleStyling) {
venkat-karasani marked this conversation as resolved.
Show resolved Hide resolved
case 'Native':
return false;
case 'Custom':
return true;
default:
// after a system update, ps4 isn't showing anything when creating a track element dynamically
// going to have to do it ourselves
if (browser.ps4) {
return true;
}

// Tizen 5 doesn't support displaying secondary subtitles
if (browser.tizenVersion >= 5 || browser.web0s) {
return true;
}
// Tizen 5 doesn't support displaying secondary subtitles
if (browser.tizenVersion >= 5 || browser.web0s) {
return true;
}

if (browser.edge) {
return true;
}
if (browser.edge) {
return true;
}

if (browser.iOS) {
const userAgent = navigator.userAgent.toLowerCase();
// works in the browser but not the native app
if ((userAgent.includes('os 9') || userAgent.includes('os 8')) && !userAgent.includes('safari')) {
return true;
}
}
// font-size styling does not seem to work natively in firefox. Switching to custom subtitles element for firefox.
venkat-karasani marked this conversation as resolved.
Show resolved Hide resolved
if (browser.firefox) {
return true;
}

return false;
if (browser.iOS) {
const userAgent = navigator.userAgent.toLowerCase();
// works in the browser but not the native app
if ((userAgent.includes('os 9') || userAgent.includes('os 8')) && !userAgent.includes('safari')) {
return true;
}
}

return false;
}
}

/**
Expand Down Expand Up @@ -1458,7 +1471,9 @@ export class HtmlVideoPlayer {
/**
* @private
*/
renderTracksEvents(videoElement, track, item, targetTextTrackIndex = PRIMARY_TEXT_TRACK_INDEX) {
async renderTracksEvents(videoElement, track, item, targetTextTrackIndex = PRIMARY_TEXT_TRACK_INDEX) {
const { userSettings } = await import('../../scripts/settings/userSettings');
venkat-karasani marked this conversation as resolved.
Show resolved Hide resolved

if (!itemHelper.isLocalItem(item) || track.IsExternal) {
const format = (track.Codec || '').toLowerCase();
if (format === 'ssa' || format === 'ass') {
Expand All @@ -1470,7 +1485,7 @@ export class HtmlVideoPlayer {
return;
}

if (this.requiresCustomSubtitlesElement()) {
if (this.requiresCustomSubtitlesElement(userSettings)) {
this.renderSubtitlesWithCustomElement(videoElement, track, item, targetTextTrackIndex);
return;
}
Expand Down Expand Up @@ -1500,28 +1515,25 @@ export class HtmlVideoPlayer {

// download the track json
this.fetchSubtitles(track, item).then(function (data) {
import('../../scripts/settings/userSettings').then((userSettings) => {
// show in ui
console.debug(`downloaded ${data.TrackEvents.length} track events`);
console.debug(`downloaded ${data.TrackEvents.length} track events`);

venkat-karasani marked this conversation as resolved.
Show resolved Hide resolved
const subtitleAppearance = userSettings.getSubtitleAppearanceSettings();
const cueLine = parseInt(subtitleAppearance.verticalPosition, 10);

// add some cues to show the text
// in safari, the cues need to be added before setting the track mode to showing
for (const trackEvent of data.TrackEvents) {
const TrackCue = window.VTTCue || window.TextTrackCue;
const cue = new TrackCue(trackEvent.StartPositionTicks / 10000000, trackEvent.EndPositionTicks / 10000000, normalizeTrackEventText(trackEvent.Text, false));
const subtitleAppearance = userSettings.getSubtitleAppearanceSettings();
const cueLine = parseInt(subtitleAppearance.verticalPosition, 10);

if (cue.line === 'auto') {
cue.line = cueLine;
}
// add some cues to show the text
// in safari, the cues need to be added before setting the track mode to showing
for (const trackEvent of data.TrackEvents) {
const TrackCue = window.VTTCue || window.TextTrackCue;
const cue = new TrackCue(trackEvent.StartPositionTicks / 10000000, trackEvent.EndPositionTicks / 10000000, normalizeTrackEventText(trackEvent.Text, false));

trackElement.addCue(cue);
if (cue.line === 'auto') {
cue.line = cueLine;
}

trackElement.mode = 'showing';
});
trackElement.addCue(cue);
}

trackElement.mode = 'showing';
});
}

Expand Down
6 changes: 6 additions & 0 deletions src/strings/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"Authorize": "Authorize",
"AuthProviderHelp": "Select an authentication provider to be used to authenticate this user's password.",
"Auto": "Auto",
"AutoSubtitleStylingHelp": "This mode will automatically switch between the native and custom subtitle styling mechanisms based on your device type.",
"Backdrop": "Backdrop",
"Backdrops": "Backdrops",
"BackdropScreensaver": "Backdrop Screensaver",
Expand Down Expand Up @@ -191,6 +192,8 @@
"Creator": "Creator",
"CriticRating": "Critics rating",
"Cursive": "Cursive",
"Custom": "Custom",
"CustomSubtitleStylingHelp": "Subtitle styling will work on most devices, but comes with an additional performance overhead.",
"DailyAt": "Daily at {0}",
"Data": "Data",
"DateAdded": "Date added",
Expand Down Expand Up @@ -906,6 +909,7 @@
"LabelStreamType": "Stream type",
"LabelSubtitleDownloaders": "Subtitle downloaders",
"LabelSubtitlePlaybackMode": "Subtitle mode",
"LabelSubtitleStyling": "Subtitle styling",
"LabelSubtitleVerticalPosition": "Vertical position",
"LabelSyncPlayAccess": "SyncPlay access",
"LabelSyncPlayAccessCreateAndJoinGroups": "Allow user to create and join groups",
Expand Down Expand Up @@ -1190,6 +1194,8 @@
"Mute": "Mute",
"MySubtitles": "My Subtitles",
"Name": "Name",
"Native": "Native",
"NativeSubtitleStylingHelp": "Subtitle styling will not work on some devices. However, it does not come with any performance overhead.",
"Never": "Never",
"New": "New",
"NewCollection": "New Collection",
Expand Down
Loading