Skip to content

Commit 1603c6d

Browse files
committed
fixed many things
1 parent d6c6e4a commit 1603c6d

File tree

5 files changed

+57
-8
lines changed

5 files changed

+57
-8
lines changed

Sora/MediaUtils/CustomPlayer/CustomPlayer.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
632632
override func viewWillAppear(_ animated: Bool) {
633633
super.viewWillAppear(animated)
634634
NotificationCenter.default.addObserver(self, selector: #selector(playerItemDidChange), name: .AVPlayerItemNewAccessLogEntry, object: nil)
635+
NotificationCenter.default.addObserver(self, selector: #selector(subtitleSettingsDidChange), name: .subtitleSettingsDidChange, object: nil)
635636
skip85Button?.isHidden = !isSkip85Visible
636637
if !isSkip85Visible {
637638
skip85Button?.alpha = 0.0
@@ -782,6 +783,15 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
782783
}
783784
}
784785

786+
@objc private func subtitleSettingsDidChange() {
787+
DispatchQueue.main.async { [weak self] in
788+
guard let self = self else { return }
789+
self.loadSubtitleSettings()
790+
self.updateSubtitleLabelAppearance()
791+
self.updateSubtitleLabelConstraints()
792+
}
793+
}
794+
785795
private func getSegmentsColor() -> Color {
786796
if let data = UserDefaults.standard.data(forKey: "segmentsColorData"),
787797
let uiColor = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? UIColor {

Sora/MediaUtils/CustomPlayer/Helpers/SubtitleSettingsManager.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
import UIKit
99

10+
extension Notification.Name {
11+
static let subtitleSettingsDidChange = Notification.Name("subtitleSettingsDidChange")
12+
}
13+
1014
struct SubtitleSettings: Codable {
1115
var enabled: Bool = true
1216
var foregroundColor: String = "white"
@@ -33,6 +37,7 @@ class SubtitleSettingsManager {
3337
set {
3438
if let data = try? JSONEncoder().encode(newValue) {
3539
UserDefaults.standard.set(data, forKey: userDefaultsKey)
40+
NotificationCenter.default.post(name: .subtitleSettingsDidChange, object: nil)
3641
}
3742
}
3843
}

Sora/MediaUtils/CustomPlayer/Helpers/VTTSubtitlesLoader.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,14 @@ class VTTSubtitlesLoader: ObservableObject {
8888
}
8989

9090
let startTime = parseTimecode(times[0].trimmingCharacters(in: .whitespaces))
91-
let adjustedStartTime = max(startTime - 0.5, 0)
9291
let endTime = parseTimecode(times[1].trimmingCharacters(in: .whitespaces))
93-
let adjusteEndTime = max(endTime - 0.5, 0)
9492
index += 1
9593
var cueText = ""
9694
while index < lines.count && !lines[index].trimmingCharacters(in: .whitespaces).isEmpty {
9795
cueText += lines[index] + "\n"
9896
index += 1
9997
}
100-
cues.append(SubtitleCue(startTime: adjustedStartTime, endTime: adjusteEndTime, text: cueText.trimmingCharacters(in: .whitespacesAndNewlines)))
98+
cues.append(SubtitleCue(startTime: startTime, endTime: endTime, text: cueText.trimmingCharacters(in: .whitespacesAndNewlines)))
10199
}
102100
return cues
103101
}
@@ -118,17 +116,15 @@ class VTTSubtitlesLoader: ObservableObject {
118116
guard times.count >= 2 else { continue }
119117

120118
let startTime = parseSRTTimecode(times[0].trimmingCharacters(in: .whitespaces))
121-
let adjustedStartTime = max(startTime - 0.5, 0)
122119
let endTime = parseSRTTimecode(times[1].trimmingCharacters(in: .whitespaces))
123-
let adjustedEndTime = max(endTime - 0.5, 0)
124120

125121
var textLines = [String]()
126122
if lines.count > 2 {
127123
textLines = Array(lines[2...])
128124
}
129125
let text = textLines.joined(separator: "\n")
130126

131-
cues.append(SubtitleCue(startTime: adjustedStartTime, endTime: adjustedEndTime, text: text))
127+
cues.append(SubtitleCue(startTime: startTime, endTime: endTime, text: text))
132128
}
133129

134130
return cues

Sora/Views/MediaInfoView/MediaInfoView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ struct MediaInfoView: View {
202202
activeFetchID = nil
203203
UserDefaults.standard.set(false, forKey: "isMediaInfoActive")
204204
UIScrollView.appearance().bounces = true
205+
NotificationCenter.default.post(name: .showTabBar, object: nil)
205206
}
206207
.task {
207208
await setupInitialData()

Sora/Views/SettingsView/SettingsSubViews/SettingsViewPlayer.swift

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,29 @@ struct SettingsViewPlayer: View {
304304
)
305305
}
306306

307+
SettingsSection(title: NSLocalizedString("Progress bar Marker Color", comment: "")) {
308+
ColorPicker(NSLocalizedString("Segments Color", comment: ""), selection: Binding(
309+
get: {
310+
if let data = UserDefaults.standard.data(forKey: "segmentsColorData"),
311+
let uiColor = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? UIColor {
312+
return Color(uiColor)
313+
}
314+
return .yellow
315+
},
316+
set: { newColor in
317+
let uiColor = UIColor(newColor)
318+
if let data = try? NSKeyedArchiver.archivedData(
319+
withRootObject: uiColor,
320+
requiringSecureCoding: false
321+
) {
322+
UserDefaults.standard.set(data, forKey: "segmentsColorData")
323+
}
324+
}
325+
))
326+
.padding(.horizontal, 16)
327+
.padding(.vertical, 12)
328+
}
329+
307330
SettingsSection(
308331
title: NSLocalizedString("Skip Settings", comment: ""),
309332
footer: NSLocalizedString("Double tapping the screen on it's sides will skip with the short tap setting.", comment: "")
@@ -439,14 +462,28 @@ struct SubtitleSettingsSection: View {
439462
title: NSLocalizedString("Bottom Padding", comment: ""),
440463
value: $bottomPadding,
441464
range: 0...50,
442-
step: 1,
443-
showDivider: false
465+
step: 1
444466
)
445467
.onChange(of: bottomPadding) { newValue in
446468
SubtitleSettingsManager.shared.update { settings in
447469
settings.bottomPadding = CGFloat(newValue)
448470
}
449471
}
472+
473+
SettingsStepperRow(
474+
icon: "clock",
475+
title: NSLocalizedString("Subtitle Delay", comment: ""),
476+
value: $subtitleDelay,
477+
range: -10...10,
478+
step: 0.1,
479+
formatter: { String(format: "%.1fs", $0) },
480+
showDivider: false
481+
)
482+
.onChange(of: subtitleDelay) { newValue in
483+
SubtitleSettingsManager.shared.update { settings in
484+
settings.subtitleDelay = newValue
485+
}
486+
}
450487
}
451488
}
452489
}

0 commit comments

Comments
 (0)