Merge pull request #276 from knbx/subtitle-sizes

Subtitle size options
This commit is contained in:
Ethan Pippin 2022-01-10 13:28:57 -07:00 committed by GitHub
commit 582cd717e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 147 additions and 8 deletions

View File

@ -0,0 +1,26 @@
//
/*
* SwiftFin is subject to the terms of the Mozilla Public
* License, v2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright 2021 Aiden Vigue & Jellyfin Contributors
*/
#if os(tvOS)
import TVVLCKit
#else
import MobileVLCKit
#endif
extension VLCMediaPlayer {
/// Applies font size to the player
///
/// This is pretty hacky until VLCKit 4 has a public API to support this
func setSubtitleSize(_ size: SubtitleSize) {
perform(
Selector(("setTextRendererFontSize:")),
with: size.textRendererFontSize
)
}
}

View File

@ -0,0 +1,59 @@
//
/*
* SwiftFin is subject to the terms of the Mozilla Public
* License, v2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright 2021 Aiden Vigue & Jellyfin Contributors
*/
import Defaults
enum SubtitleSize: Int32, CaseIterable, Defaults.Serializable {
case smallest
case smaller
case regular
case larger
case largest
}
// MARK: - appearance
extension SubtitleSize {
var label: String {
switch self {
case .smallest:
return "Smallest"
case .smaller:
return "Smaller"
case .regular:
return "Regular"
case .larger:
return "Larger"
case .largest:
return "Largest"
}
}
}
// MARK: - sizing for VLC
extension SubtitleSize {
/// Value to be passed to VLCKit (via hacky internal property, until VLCKit 4)
///
/// note that it doesn't correspond to actual font sizes; a smaller int creates bigger text
var textRendererFontSize: Int {
switch self {
case .smallest:
return 24
case .smaller:
return 20
case .regular:
return 16
case .larger:
return 12
case .largest:
return 8
}
}
}

View File

@ -49,6 +49,7 @@ extension Defaults.Keys {
static let videoPlayerJumpBackward = Key<VideoPlayerJumpLength>("videoPlayerJumpBackward", default: .fifteen, suite: SwiftfinStore.Defaults.generalSuite)
static let autoplayEnabled = Key<Bool>("autoPlayNextItem", default: true, suite: SwiftfinStore.Defaults.generalSuite)
static let resumeOffset = Key<Bool>("resumeOffset", default: false, suite: SwiftfinStore.Defaults.generalSuite)
static let subtitleSize = Key<SubtitleSize>("subtitleSize", default: .regular, suite: SwiftfinStore.Defaults.generalSuite)
// Should show video player items
static let shouldShowPlayPreviousItem = Key<Bool>("shouldShowPreviousItem", default: true, suite: SwiftfinStore.Defaults.generalSuite)

View File

@ -23,6 +23,7 @@ struct SettingsView: View {
@Default(.tvOSCinematicViews) var tvOSCinematicViews
@Default(.showPosterLabels) var showPosterLabels
@Default(.resumeOffset) var resumeOffset
@Default(.subtitleSize) var subtitleSize
var body: some View {
GeometryReader { reader in
@ -115,11 +116,19 @@ struct SettingsView: View {
Section {
Toggle("Cinematic Views", isOn: $tvOSCinematicViews)
Toggle("Show Poster Labels", isOn: $showPosterLabels)
} header: {
Text("Appearance")
}
Section(header: L10n.accessibility.text) {
Toggle("Show Poster Labels", isOn: $showPosterLabels)
Picker("Subtitle size", selection: $subtitleSize) {
ForEach(SubtitleSize.allCases, id: \.self) { size in
Text(size.label).tag(size.rawValue)
}
}
}
}
}
}

View File

@ -395,9 +395,8 @@ extension VLCPlayerViewController {
vlcMediaPlayer.delegate = self
vlcMediaPlayer.drawable = videoContentView
// TODO: Custom subtitle sizes
vlcMediaPlayer.perform(Selector(("setTextRendererFontSize:")), with: 16)
vlcMediaPlayer.setSubtitleSize(Defaults[.subtitleSize])
stopOverlayDismissTimer()

View File

@ -138,6 +138,11 @@
53EE24E6265060780068F029 /* LibrarySearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53EE24E5265060780068F029 /* LibrarySearchView.swift */; };
53F866442687A45F00DCD1D7 /* PortraitItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53F866432687A45F00DCD1D7 /* PortraitItemView.swift */; };
53FF7F2A263CF3F500585C35 /* LatestMediaView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53FF7F29263CF3F500585C35 /* LatestMediaView.swift */; };
5D1603FC278A3D5800D22B99 /* SubtitleSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1603FB278A3D5700D22B99 /* SubtitleSize.swift */; };
5D1603FD278A40DB00D22B99 /* SubtitleSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1603FB278A3D5700D22B99 /* SubtitleSize.swift */; };
5D1603FE278A40DC00D22B99 /* SubtitleSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1603FB278A3D5700D22B99 /* SubtitleSize.swift */; };
5D160403278A41FD00D22B99 /* VLCPlayer+subtitles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D160402278A41FD00D22B99 /* VLCPlayer+subtitles.swift */; };
5D32EA12278C95E30020E292 /* VLCPlayer+subtitles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D160402278A41FD00D22B99 /* VLCPlayer+subtitles.swift */; };
5D64683D277B1649009E09AE /* PreferenceUIHostingSwizzling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D64683C277B1649009E09AE /* PreferenceUIHostingSwizzling.swift */; };
62133890265F83A900A81A2A /* LibraryListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6213388F265F83A900A81A2A /* LibraryListView.swift */; };
621338932660107500A81A2A /* StringExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621338922660107500A81A2A /* StringExtensions.swift */; };
@ -572,6 +577,8 @@
53EE24E5265060780068F029 /* LibrarySearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibrarySearchView.swift; sourceTree = "<group>"; };
53F866432687A45F00DCD1D7 /* PortraitItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PortraitItemView.swift; sourceTree = "<group>"; };
53FF7F29263CF3F500585C35 /* LatestMediaView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LatestMediaView.swift; sourceTree = "<group>"; };
5D1603FB278A3D5700D22B99 /* SubtitleSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubtitleSize.swift; sourceTree = "<group>"; };
5D160402278A41FD00D22B99 /* VLCPlayer+subtitles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "VLCPlayer+subtitles.swift"; sourceTree = "<group>"; };
5D64683C277B1649009E09AE /* PreferenceUIHostingSwizzling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferenceUIHostingSwizzling.swift; sourceTree = "<group>"; };
6213388F265F83A900A81A2A /* LibraryListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryListView.swift; sourceTree = "<group>"; };
621338922660107500A81A2A /* StringExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtensions.swift; sourceTree = "<group>"; };
@ -976,6 +983,7 @@
E193D4DA27193CCA00900D82 /* PillStackable.swift */,
E193D4D727193CAC00900D82 /* PortraitImageStackable.swift */,
E10D87DD278510E300BD264C /* PosterSize.swift */,
5D1603FB278A3D5700D22B99 /* SubtitleSize.swift */,
E1D4BF832719D25A00A11E64 /* TrackLanguage.swift */,
535870AC2669D8DD00D05A09 /* Typings.swift */,
E1F0204D26CCCA74001C1C3B /* VideoPlayerJumpLength.swift */,
@ -1034,6 +1042,7 @@
62ECA01926FA6D6900E8EBB7 /* AppURLHandler */,
5377CBF8263B596B003A4E83 /* Assets.xcassets */,
53F866422687A45400DCD1D7 /* Components */,
5D160401278A41BA00D22B99 /* Extensions */,
5377CC02263B596B003A4E83 /* Info.plist */,
E13D02842788B634000FCB04 /* Swiftfin.entitlements */,
5377CBFA263B596B003A4E83 /* Preview Content */,
@ -1214,6 +1223,13 @@
path = Components;
sourceTree = "<group>";
};
5D160401278A41BA00D22B99 /* Extensions */ = {
isa = PBXGroup;
children = (
);
path = Extensions;
sourceTree = "<group>";
};
5D64683B277B15E4009E09AE /* PreferenceUIHosting */ = {
isa = PBXGroup;
children = (
@ -1237,6 +1253,7 @@
E13DD3C727164B1E009D4DAF /* UIDeviceExtensions.swift */,
E1C812C4277A90B200918266 /* URLComponentsExtensions.swift */,
62E1DCC2273CE19800C9AE76 /* URLExtensions.swift */,
5D160402278A41FD00D22B99 /* VLCPlayer+subtitles.swift */,
6220D0AC26D5EABB00B8E046 /* ViewExtensions.swift */,
);
path = Extensions;
@ -1665,6 +1682,7 @@
buildPhases = (
3D0F2756C71CDF6B9EEBD4E0 /* [CP] Check Pods Manifest.lock */,
6286F0A3271C0ABA00C40ED5 /* R.swift */,
C6EE6AB295A273FF14E6EF56 /* [CP] Prepare Artifacts */,
5358705C2669D21600D05A09 /* Sources */,
5358705D2669D21600D05A09 /* Frameworks */,
5358705E2669D21600D05A09 /* Resources */,
@ -2023,6 +2041,23 @@
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Swiftfin iOS/Pods-Swiftfin iOS-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
C6EE6AB295A273FF14E6EF56 /* [CP] Prepare Artifacts */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Swiftfin tvOS/Pods-Swiftfin tvOS-artifacts-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Prepare Artifacts";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Swiftfin tvOS/Pods-Swiftfin tvOS-artifacts-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Swiftfin tvOS/Pods-Swiftfin tvOS-artifacts.sh\"\n";
showEnvVarsInLog = 0;
};
D4D3981ADF75BCD341D590C0 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@ -2086,6 +2121,7 @@
E13DD3F027178F87009D4DAF /* SwiftfinNotificationCenter.swift in Sources */,
531690E7267ABD79005D8AB9 /* HomeView.swift in Sources */,
E11D224327378428003F9CB3 /* ServerDetailCoordinator.swift in Sources */,
5D32EA12278C95E30020E292 /* VLCPlayer+subtitles.swift in Sources */,
E1D4BF8B2719D3D000A11E64 /* BasicAppSettingsCoordinator.swift in Sources */,
E1E5D53B2783A80900692DFE /* CinematicItemViewTopRow.swift in Sources */,
E13DD3FA2717E961009D4DAF /* UserListViewModel.swift in Sources */,
@ -2163,6 +2199,7 @@
E1AD104E26D96CE3003E4A08 /* BaseItemDtoExtensions.swift in Sources */,
62E632DD267D2E130063E547 /* LibrarySearchViewModel.swift in Sources */,
536D3D81267BDFC60004248C /* PortraitItemElement.swift in Sources */,
5D1603FD278A40DB00D22B99 /* SubtitleSize.swift in Sources */,
E1AA33232782648000F6439C /* OverlaySliderColor.swift in Sources */,
E103A6A7278AB6D700820EC7 /* CinematicResumeCardView.swift in Sources */,
62E1DCC4273CE19800C9AE76 /* URLExtensions.swift in Sources */,
@ -2272,6 +2309,7 @@
E13DD3EC27178A54009D4DAF /* UserSignInViewModel.swift in Sources */,
625CB5772678C34300530A6E /* ConnectToServerViewModel.swift in Sources */,
C4BE07852728446F003F4AD1 /* LiveTVChannelsViewModel.swift in Sources */,
5D160403278A41FD00D22B99 /* VLCPlayer+subtitles.swift in Sources */,
536D3D78267BD5C30004248C /* ViewModel.swift in Sources */,
C4BE078B272844AF003F4AD1 /* LiveTVChannelsView.swift in Sources */,
E1FCD08826C35A0D007C8DCF /* NetworkError.swift in Sources */,
@ -2312,6 +2350,7 @@
091B5A8B2683142E00D78B61 /* UDPBroadCastConnection.swift in Sources */,
6267B3D626710B8900A7371D /* CollectionExtensions.swift in Sources */,
E13DD3F5271793BB009D4DAF /* UserSignInView.swift in Sources */,
5D1603FC278A3D5800D22B99 /* SubtitleSize.swift in Sources */,
E1F0204E26CCCA74001C1C3B /* VideoPlayerJumpLength.swift in Sources */,
53649AB1269CFB1900A2D8B7 /* LogManager.swift in Sources */,
E13DD3E127176BD3009D4DAF /* ServerListViewModel.swift in Sources */,
@ -2426,6 +2465,7 @@
62E1DCC5273CE19800C9AE76 /* URLExtensions.swift in Sources */,
62EC353226766849000E9F2D /* SessionManager.swift in Sources */,
536D3D79267BD5D00004248C /* ViewModel.swift in Sources */,
5D1603FE278A40DC00D22B99 /* SubtitleSize.swift in Sources */,
E1AA332427829B5200F6439C /* OverlayType.swift in Sources */,
E1D4BF8C2719F39F00A11E64 /* AppAppearance.swift in Sources */,
);

View File

@ -28,6 +28,7 @@ struct SettingsView: View {
@Default(.showPosterLabels) var showPosterLabels
@Default(.showCastAndCrew) var showCastAndCrew
@Default(.resumeOffset) var resumeOffset
@Default(.subtitleSize) var subtitleSize
var body: some View {
Form {
@ -128,6 +129,11 @@ struct SettingsView: View {
Text(appearance.localizedName).tag(appearance.rawValue)
}
}
Picker("Subtitle size", selection: $subtitleSize) {
ForEach(SubtitleSize.allCases, id: \.self) { size in
Text(size.label).tag(size.rawValue)
}
}
}
}
.navigationBarTitle("Settings", displayMode: .inline)

View File

@ -298,9 +298,8 @@ extension VLCPlayerViewController {
vlcMediaPlayer.delegate = self
vlcMediaPlayer.drawable = videoContentView
// TODO: Custom subtitle sizes
vlcMediaPlayer.perform(Selector(("setTextRendererFontSize:")), with: 14)
vlcMediaPlayer.setSubtitleSize(Defaults[.subtitleSize])
stopOverlayDismissTimer()