mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-21 16:42:01 +00:00
fixed many things
This commit is contained in:
parent
d6c6e4a1aa
commit
1603c6df8c
5 changed files with 57 additions and 8 deletions
|
|
@ -632,6 +632,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(playerItemDidChange), name: .AVPlayerItemNewAccessLogEntry, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(playerItemDidChange), name: .AVPlayerItemNewAccessLogEntry, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(subtitleSettingsDidChange), name: .subtitleSettingsDidChange, object: nil)
|
||||||
skip85Button?.isHidden = !isSkip85Visible
|
skip85Button?.isHidden = !isSkip85Visible
|
||||||
if !isSkip85Visible {
|
if !isSkip85Visible {
|
||||||
skip85Button?.alpha = 0.0
|
skip85Button?.alpha = 0.0
|
||||||
|
|
@ -782,6 +783,15 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc private func subtitleSettingsDidChange() {
|
||||||
|
DispatchQueue.main.async { [weak self] in
|
||||||
|
guard let self = self else { return }
|
||||||
|
self.loadSubtitleSettings()
|
||||||
|
self.updateSubtitleLabelAppearance()
|
||||||
|
self.updateSubtitleLabelConstraints()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func getSegmentsColor() -> Color {
|
private func getSegmentsColor() -> Color {
|
||||||
if let data = UserDefaults.standard.data(forKey: "segmentsColorData"),
|
if let data = UserDefaults.standard.data(forKey: "segmentsColorData"),
|
||||||
let uiColor = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? UIColor {
|
let uiColor = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? UIColor {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
extension Notification.Name {
|
||||||
|
static let subtitleSettingsDidChange = Notification.Name("subtitleSettingsDidChange")
|
||||||
|
}
|
||||||
|
|
||||||
struct SubtitleSettings: Codable {
|
struct SubtitleSettings: Codable {
|
||||||
var enabled: Bool = true
|
var enabled: Bool = true
|
||||||
var foregroundColor: String = "white"
|
var foregroundColor: String = "white"
|
||||||
|
|
@ -33,6 +37,7 @@ class SubtitleSettingsManager {
|
||||||
set {
|
set {
|
||||||
if let data = try? JSONEncoder().encode(newValue) {
|
if let data = try? JSONEncoder().encode(newValue) {
|
||||||
UserDefaults.standard.set(data, forKey: userDefaultsKey)
|
UserDefaults.standard.set(data, forKey: userDefaultsKey)
|
||||||
|
NotificationCenter.default.post(name: .subtitleSettingsDidChange, object: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,16 +88,14 @@ class VTTSubtitlesLoader: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
let startTime = parseTimecode(times[0].trimmingCharacters(in: .whitespaces))
|
let startTime = parseTimecode(times[0].trimmingCharacters(in: .whitespaces))
|
||||||
let adjustedStartTime = max(startTime - 0.5, 0)
|
|
||||||
let endTime = parseTimecode(times[1].trimmingCharacters(in: .whitespaces))
|
let endTime = parseTimecode(times[1].trimmingCharacters(in: .whitespaces))
|
||||||
let adjusteEndTime = max(endTime - 0.5, 0)
|
|
||||||
index += 1
|
index += 1
|
||||||
var cueText = ""
|
var cueText = ""
|
||||||
while index < lines.count && !lines[index].trimmingCharacters(in: .whitespaces).isEmpty {
|
while index < lines.count && !lines[index].trimmingCharacters(in: .whitespaces).isEmpty {
|
||||||
cueText += lines[index] + "\n"
|
cueText += lines[index] + "\n"
|
||||||
index += 1
|
index += 1
|
||||||
}
|
}
|
||||||
cues.append(SubtitleCue(startTime: adjustedStartTime, endTime: adjusteEndTime, text: cueText.trimmingCharacters(in: .whitespacesAndNewlines)))
|
cues.append(SubtitleCue(startTime: startTime, endTime: endTime, text: cueText.trimmingCharacters(in: .whitespacesAndNewlines)))
|
||||||
}
|
}
|
||||||
return cues
|
return cues
|
||||||
}
|
}
|
||||||
|
|
@ -118,9 +116,7 @@ class VTTSubtitlesLoader: ObservableObject {
|
||||||
guard times.count >= 2 else { continue }
|
guard times.count >= 2 else { continue }
|
||||||
|
|
||||||
let startTime = parseSRTTimecode(times[0].trimmingCharacters(in: .whitespaces))
|
let startTime = parseSRTTimecode(times[0].trimmingCharacters(in: .whitespaces))
|
||||||
let adjustedStartTime = max(startTime - 0.5, 0)
|
|
||||||
let endTime = parseSRTTimecode(times[1].trimmingCharacters(in: .whitespaces))
|
let endTime = parseSRTTimecode(times[1].trimmingCharacters(in: .whitespaces))
|
||||||
let adjustedEndTime = max(endTime - 0.5, 0)
|
|
||||||
|
|
||||||
var textLines = [String]()
|
var textLines = [String]()
|
||||||
if lines.count > 2 {
|
if lines.count > 2 {
|
||||||
|
|
@ -128,7 +124,7 @@ class VTTSubtitlesLoader: ObservableObject {
|
||||||
}
|
}
|
||||||
let text = textLines.joined(separator: "\n")
|
let text = textLines.joined(separator: "\n")
|
||||||
|
|
||||||
cues.append(SubtitleCue(startTime: adjustedStartTime, endTime: adjustedEndTime, text: text))
|
cues.append(SubtitleCue(startTime: startTime, endTime: endTime, text: text))
|
||||||
}
|
}
|
||||||
|
|
||||||
return cues
|
return cues
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,7 @@ struct MediaInfoView: View {
|
||||||
activeFetchID = nil
|
activeFetchID = nil
|
||||||
UserDefaults.standard.set(false, forKey: "isMediaInfoActive")
|
UserDefaults.standard.set(false, forKey: "isMediaInfoActive")
|
||||||
UIScrollView.appearance().bounces = true
|
UIScrollView.appearance().bounces = true
|
||||||
|
NotificationCenter.default.post(name: .showTabBar, object: nil)
|
||||||
}
|
}
|
||||||
.task {
|
.task {
|
||||||
await setupInitialData()
|
await setupInitialData()
|
||||||
|
|
|
||||||
|
|
@ -304,6 +304,29 @@ struct SettingsViewPlayer: View {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsSection(title: NSLocalizedString("Progress bar Marker Color", comment: "")) {
|
||||||
|
ColorPicker(NSLocalizedString("Segments Color", comment: ""), selection: Binding(
|
||||||
|
get: {
|
||||||
|
if let data = UserDefaults.standard.data(forKey: "segmentsColorData"),
|
||||||
|
let uiColor = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? UIColor {
|
||||||
|
return Color(uiColor)
|
||||||
|
}
|
||||||
|
return .yellow
|
||||||
|
},
|
||||||
|
set: { newColor in
|
||||||
|
let uiColor = UIColor(newColor)
|
||||||
|
if let data = try? NSKeyedArchiver.archivedData(
|
||||||
|
withRootObject: uiColor,
|
||||||
|
requiringSecureCoding: false
|
||||||
|
) {
|
||||||
|
UserDefaults.standard.set(data, forKey: "segmentsColorData")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
))
|
||||||
|
.padding(.horizontal, 16)
|
||||||
|
.padding(.vertical, 12)
|
||||||
|
}
|
||||||
|
|
||||||
SettingsSection(
|
SettingsSection(
|
||||||
title: NSLocalizedString("Skip Settings", comment: ""),
|
title: NSLocalizedString("Skip Settings", comment: ""),
|
||||||
footer: NSLocalizedString("Double tapping the screen on it's sides will skip with the short tap setting.", comment: "")
|
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 {
|
||||||
title: NSLocalizedString("Bottom Padding", comment: ""),
|
title: NSLocalizedString("Bottom Padding", comment: ""),
|
||||||
value: $bottomPadding,
|
value: $bottomPadding,
|
||||||
range: 0...50,
|
range: 0...50,
|
||||||
step: 1,
|
step: 1
|
||||||
showDivider: false
|
|
||||||
)
|
)
|
||||||
.onChange(of: bottomPadding) { newValue in
|
.onChange(of: bottomPadding) { newValue in
|
||||||
SubtitleSettingsManager.shared.update { settings in
|
SubtitleSettingsManager.shared.update { settings in
|
||||||
settings.bottomPadding = CGFloat(newValue)
|
settings.bottomPadding = CGFloat(newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsStepperRow(
|
||||||
|
icon: "clock",
|
||||||
|
title: NSLocalizedString("Subtitle Delay", comment: ""),
|
||||||
|
value: $subtitleDelay,
|
||||||
|
range: -10...10,
|
||||||
|
step: 0.1,
|
||||||
|
formatter: { String(format: "%.1fs", $0) },
|
||||||
|
showDivider: false
|
||||||
|
)
|
||||||
|
.onChange(of: subtitleDelay) { newValue in
|
||||||
|
SubtitleSettingsManager.shared.update { settings in
|
||||||
|
settings.subtitleDelay = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue