Skip to content

Commit

Permalink
feat: global subtitle display setting
Browse files Browse the repository at this point in the history
You can now activate/deactivate the visiblity of
subtitles on a global application level.
  • Loading branch information
4gray committed Sep 5, 2021
1 parent 3dd2789 commit 4d2e175
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class HtmlVideoPlayerComponent implements OnChanges, OnDestroy {
/** HLS object */
hls: Hls;

/** Captions/subtitles indicator */
@Input() showCaptions!: boolean;

/**
* Listen for component input changes
* @param changes component changes
Expand Down Expand Up @@ -54,6 +57,19 @@ export class HtmlVideoPlayerComponent implements OnChanges, OnDestroy {
}
}

/**
* Disables text based captions based on the global settings
*/
disableCaptions(): void {
for (
let i = 0;
i < this.videoPlayer.nativeElement.textTracks.length;
i++
) {
this.videoPlayer.nativeElement.textTracks[i].mode = 'hidden';
}
}

/**
* Handles promise based play operation
*/
Expand All @@ -64,6 +80,9 @@ export class HtmlVideoPlayerComponent implements OnChanges, OnDestroy {
playPromise
.then((_) => {
// Automatic playback started!
if (!this.showCaptions) {
this.disableCaptions();
}
})
.catch((error) => {});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

<!-- video.js player -->
<app-vjs-player
*ngIf="player === 'videojs'"
*ngIf="playerSettings.player === 'videojs'"
[options]="{
sources: [
{
Expand All @@ -60,12 +60,14 @@
}
]
}"
[class.hide-captions]="!playerSettings.showCaptions"
></app-vjs-player>
</ng-container>
<!-- default html player component -->
<app-html-video-player
*ngIf="player === 'html5'"
*ngIf="playerSettings.player === 'html5'"
[channel]="activeChannel$ | async"
[showCaptions]="playerSettings.showCaptions"
>
</app-html-video-player>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as MOCKED_PLAYLIST from '../../../../mocks/playlist.json';
import { createChannel } from '../../../state';
import { HtmlVideoPlayerComponent } from '../html-video-player/html-video-player.component';
import { EpgListComponent } from '../epg-list/epg-list.component';
import { VideoPlayer } from '../../../settings/settings.interface';

class MatSnackBarStub {
open(): void {}
Expand Down Expand Up @@ -73,7 +74,10 @@ describe('VideoPlayerComponent', () => {

it('should check default component settings', () => {
fixture.detectChanges();
expect(component.player).toEqual('videojs');
expect(component.playerSettings).toEqual({
player: VideoPlayer.VideoJs,
showCaptions: false,
});
});

it('should update store after channel was faved', () => {
Expand Down
17 changes: 10 additions & 7 deletions src/app/player/components/video-player/video-player.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { MatSidenav } from '@angular/material/sidenav';
import { StorageMap } from '@ngx-pwa/local-storage';
import {
Settings,
VideoPlayerType,
} from '../../../settings/settings.interface';
import { Settings, VideoPlayer } from '../../../settings/settings.interface';
import { MatSnackBar } from '@angular/material/snack-bar';

/** Settings key in storage */
Expand Down Expand Up @@ -46,8 +43,11 @@ export class VideoPlayerComponent implements OnInit {
(store) => store.favorites
);

/** Selected video player component */
player: VideoPlayerType = 'videojs';
/** Selected video player options */
playerSettings: Partial<Settings> = {
player: VideoPlayer.VideoJs,
showCaptions: false,
};

/** Sidebar object */
@ViewChild('sidenav') sideNav: MatSidenav;
Expand Down Expand Up @@ -79,7 +79,10 @@ export class VideoPlayerComponent implements OnInit {
applySettings(): void {
this.storage.get(SETTINGS_STORE_KEY).subscribe((settings: Settings) => {
if (settings && Object.keys(settings).length > 0) {
this.player = settings.player;
this.playerSettings = {
player: settings.player,
showCaptions: settings.showCaptions,
};
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@
width: 100% !important;
height: calc(100vh - 85px);
}

/* Hide the captions settings item from the captions menu. */
.hide-captions {
.vjs-texttrack-settings,
.vjs-text-track-display,
.vjs-subs-caps-button {
display: none;
}
}
10 changes: 10 additions & 0 deletions src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@
</p>
</div>
</mat-list-item>
<mat-list-item>
<div matLine fxLayout="row">
<p fxFlex>{{ 'SETTINGS.SHOW_CAPTIONS' | translate }}</p>
<p fxFlex>
<mat-checkbox
formControlName="showCaptions"
></mat-checkbox>
</p>
</div>
</mat-list-item>
<mat-list-item>
<div matLine fxLayout="row">
<p fxFlex>{{ 'SETTINGS.VERSION' | translate }}</p>
Expand Down
2 changes: 2 additions & 0 deletions src/app/settings/settings.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MatCheckboxModule } from '@angular/material/checkbox';
import { StorageMap } from '@ngx-pwa/local-storage';
import { FormBuilder } from '@angular/forms';
/* eslint-disable @typescript-eslint/unbound-method */
Expand Down Expand Up @@ -72,6 +73,7 @@ describe('SettingsComponent', () => {
MockModule(MatCardModule),
MockModule(MatListModule),
MockModule(MatFormFieldModule),
MockModule(MatCheckboxModule),
],
}).compileComponents();
})
Expand Down
16 changes: 11 additions & 5 deletions src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StorageMap } from '@ngx-pwa/local-storage';
import { Router } from '@angular/router';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Observable, Subscription } from 'rxjs';
import { Settings } from './settings.interface';
import { Settings, VideoPlayer } from './settings.interface';
import { HttpClient } from '@angular/common/http';
import * as semver from 'semver';
import { ElectronService } from '../services/electron.service';
Expand Down Expand Up @@ -34,11 +34,11 @@ export class SettingsComponent implements OnInit, OnDestroy {
/** Player options */
players = [
{
id: 'html5',
id: VideoPlayer.Html5Player,
label: 'HTML5 Video Player',
},
{
id: 'videojs',
id: VideoPlayer.VideoJs,
label: 'VideoJs Player',
},
];
Expand Down Expand Up @@ -84,9 +84,10 @@ export class SettingsComponent implements OnInit, OnDestroy {
private translate: TranslateService
) {
this.settingsForm = this.formBuilder.group({
player: ['videojs'],
player: [VideoPlayer.VideoJs],
epgUrl: '',
language: Language.ENGLISH,
showCaptions: false,
theme: Theme.LightTheme,
});

Expand Down Expand Up @@ -123,11 +124,16 @@ export class SettingsComponent implements OnInit, OnDestroy {
this.storage.get('settings').subscribe((settings: Settings) => {
if (settings) {
this.settingsForm.setValue({
player: settings.player ? settings.player : 'videojs',
player: settings.player
? settings.player
: VideoPlayer.VideoJs,
epgUrl: settings.epgUrl ? settings.epgUrl : '',
language: settings.language
? settings.language
: Language.ENGLISH,
showCaptions: settings.showCaptions
? settings.showCaptions
: false,
theme: settings.theme
? settings.theme
: Theme.LightTheme,
Expand Down
8 changes: 6 additions & 2 deletions src/app/settings/settings.interface.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Language } from './language.enum';
import { Theme } from './theme.enum';

export type VideoPlayerType = 'html5' | 'videojs';
export enum VideoPlayer {
VideoJs = 'videojs',
Html5Player = 'html5',
}

/**
* Describes all available settings options of the application
*/
export interface Settings {
player: VideoPlayerType;
player: VideoPlayer;
epgUrl: string;
language: Language;
showCaptions: boolean;
theme: Theme;
}
5 changes: 3 additions & 2 deletions src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"PROGRAM_DIALOG": {
"PROGRAM_DETAILS": "Details zum TV-Programm",
"TITLE": "Titel",
"CATEGORY": "Ketegorie",
"CATEGORY": "Kategorie",
"PARENTAL_RATING_SYSTEM": "Alterskennzeichnung (USK)",
"DESCRIPTION": "Beschreibung",
"LANGUAGE": "Sprache",
Expand Down Expand Up @@ -105,7 +105,8 @@
"VIDEO_PLAYER_LABEL": "Video player",
"VIDEO_PLAYER_PLACEHOLDER": "Option auswählen",
"SETTINGS_SAVED": "Einstellungen wurden erfolgreich gespeichert!",
"THEME": "Farbdesign"
"THEME": "Farbdesign",
"SHOW_CAPTIONS": "Untertitel anzeigen"
},
"THEMES": {
"DARK_THEME": "Dunkel",
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"LATEST_VERSION": "You are using the latest version",
"LANGUAGE": "Language",
"SETTINGS_SAVED": "Success! Configuration was saved.",
"THEME": "Visual theme"
"THEME": "Visual theme",
"SHOW_CAPTIONS": "Show subtitles"
},
"THEMES": {
"DARK_THEME": "Dark theme",
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"LATEST_VERSION": "Estás usando la versión reciente",
"LANGUAGE": "Idioma",
"SETTINGS_SAVED": "¡Completado! La configuración se guardó.",
"THEME": "Tema visual"
"THEME": "Tema visual",
"SHOW_CAPTIONS": "Mostrar subtítulos"
},
"THEMES": {
"DARK_THEME": "Tema oscuro",
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"LATEST_VERSION": "최신 버전을 사용하고 있습니다",
"LANGUAGE": "언어",
"SETTINGS_SAVED": "설정이 저장되었습니다.",
"THEME": "테마"
"THEME": "테마",
"SHOW_CAPTIONS": "Show subtitles"
},
"THEMES": {
"DARK_THEME": "어두운 테마",
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"LATEST_VERSION": "Вы используете последнюю версию приложения",
"LANGUAGE": "Язык",
"SETTINGS_SAVED": "Новые настройки были успешно сохранены!",
"THEME": "Тема оформления"
"THEME": "Тема оформления",
"SHOW_CAPTIONS": "Отображать субтитры"
},
"THEMES": {
"DARK_THEME": "Тёмная тема",
Expand Down

0 comments on commit 4d2e175

Please sign in to comment.