@neoskola/auto-play 0.3.12 → 0.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -42,7 +42,7 @@ class NowPlayingTemplate: NSObject, AutoPlayTemplate, CPMapTemplateDelegate {
|
|
|
42
42
|
super.init()
|
|
43
43
|
|
|
44
44
|
template.mapDelegate = self
|
|
45
|
-
template.mapButtons =
|
|
45
|
+
template.mapButtons = Self.buildMapButtons(isPlaying: config.isPlaying, owner: self)
|
|
46
46
|
|
|
47
47
|
DispatchQueue.main.async { [weak self] in
|
|
48
48
|
guard let self = self else { return }
|
|
@@ -57,6 +57,52 @@ class NowPlayingTemplate: NSObject, AutoPlayTemplate, CPMapTemplateDelegate {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
// MARK: - CPMapButton Controls
|
|
61
|
+
|
|
62
|
+
private static func buildMapButtons(isPlaying: Bool, owner: NowPlayingTemplate) -> [CPMapButton] {
|
|
63
|
+
let buttonSize = CPButtonMaximumImageSize
|
|
64
|
+
|
|
65
|
+
// Previous track button
|
|
66
|
+
let prevImage = UIImage(systemName: "backward.end.fill")?
|
|
67
|
+
.withTintColor(.white, renderingMode: .alwaysOriginal)
|
|
68
|
+
.resized(to: buttonSize)
|
|
69
|
+
let prevButton = CPMapButton(image: prevImage ?? UIImage()) { [weak owner] _ in
|
|
70
|
+
owner?.config.onPreviousTrack?()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Play/Pause button
|
|
74
|
+
let playPauseIconName = isPlaying ? "pause.circle.fill" : "play.circle.fill"
|
|
75
|
+
let playPauseImage = UIImage(systemName: playPauseIconName)?
|
|
76
|
+
.withTintColor(.white, renderingMode: .alwaysOriginal)
|
|
77
|
+
.resized(to: buttonSize)
|
|
78
|
+
let playPauseButton = CPMapButton(image: playPauseImage ?? UIImage()) { [weak owner] _ in
|
|
79
|
+
guard let owner = owner else { return }
|
|
80
|
+
DispatchQueue.main.async {
|
|
81
|
+
if owner.config.isPlaying {
|
|
82
|
+
owner.pauseAudio()
|
|
83
|
+
owner.config.onPause?()
|
|
84
|
+
} else {
|
|
85
|
+
owner.resumeAudio()
|
|
86
|
+
owner.config.onPlay?()
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Next track button
|
|
92
|
+
let nextImage = UIImage(systemName: "forward.end.fill")?
|
|
93
|
+
.withTintColor(.white, renderingMode: .alwaysOriginal)
|
|
94
|
+
.resized(to: buttonSize)
|
|
95
|
+
let nextButton = CPMapButton(image: nextImage ?? UIImage()) { [weak owner] _ in
|
|
96
|
+
owner?.config.onNextTrack?()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return [prevButton, playPauseButton, nextButton]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private func updateMapButtons() {
|
|
103
|
+
template.mapButtons = Self.buildMapButtons(isPlaying: config.isPlaying, owner: self)
|
|
104
|
+
}
|
|
105
|
+
|
|
60
106
|
// MARK: - Custom View Injection
|
|
61
107
|
|
|
62
108
|
@MainActor
|
|
@@ -75,26 +121,6 @@ class NowPlayingTemplate: NSObject, AutoPlayTemplate, CPMapTemplateDelegate {
|
|
|
75
121
|
customVC.updateInfo(courseName: subtitleText, lessonName: titleText)
|
|
76
122
|
customVC.updatePlaybackState(isPlaying: config.isPlaying)
|
|
77
123
|
|
|
78
|
-
// Wire button callbacks
|
|
79
|
-
customVC.onPreviousTrack = { [weak self] in
|
|
80
|
-
self?.config.onPreviousTrack?()
|
|
81
|
-
}
|
|
82
|
-
customVC.onPlayPause = { [weak self] in
|
|
83
|
-
guard let self = self else { return }
|
|
84
|
-
DispatchQueue.main.async {
|
|
85
|
-
if self.config.isPlaying {
|
|
86
|
-
self.pauseAudio()
|
|
87
|
-
self.config.onPause?()
|
|
88
|
-
} else {
|
|
89
|
-
self.resumeAudio()
|
|
90
|
-
self.config.onPlay?()
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
customVC.onNextTrack = { [weak self] in
|
|
95
|
-
self?.config.onNextTrack?()
|
|
96
|
-
}
|
|
97
|
-
|
|
98
124
|
window.rootViewController = customVC
|
|
99
125
|
window.makeKeyAndVisible()
|
|
100
126
|
|
|
@@ -124,6 +150,7 @@ class NowPlayingTemplate: NSObject, AutoPlayTemplate, CPMapTemplateDelegate {
|
|
|
124
150
|
customVC.updateInfo(courseName: subtitleText, lessonName: titleText)
|
|
125
151
|
customVC.updatePlaybackState(isPlaying: config.isPlaying)
|
|
126
152
|
customVC.updateTime(elapsed: currentElapsedTime, duration: currentDuration)
|
|
153
|
+
updateMapButtons()
|
|
127
154
|
}
|
|
128
155
|
|
|
129
156
|
// MARK: - Native Audio Playback
|
|
@@ -12,17 +12,6 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
12
12
|
private let durationLabel = UILabel()
|
|
13
13
|
private let timeStack = UIStackView()
|
|
14
14
|
|
|
15
|
-
// MARK: - Button Controls
|
|
16
|
-
private let buttonStack = UIStackView()
|
|
17
|
-
private let previousButton = UIButton(type: .system)
|
|
18
|
-
private let playPauseButton = UIButton(type: .system)
|
|
19
|
-
private let nextButton = UIButton(type: .system)
|
|
20
|
-
|
|
21
|
-
// MARK: - Callbacks
|
|
22
|
-
var onPreviousTrack: (() -> Void)?
|
|
23
|
-
var onPlayPause: (() -> Void)?
|
|
24
|
-
var onNextTrack: (() -> Void)?
|
|
25
|
-
|
|
26
15
|
// MARK: - Lifecycle
|
|
27
16
|
|
|
28
17
|
override func viewDidLoad() {
|
|
@@ -77,42 +66,6 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
77
66
|
timeStack.addArrangedSubview(currentTimeLabel)
|
|
78
67
|
timeStack.addArrangedSubview(durationLabel)
|
|
79
68
|
|
|
80
|
-
// Previous Button
|
|
81
|
-
previousButton.setImage(
|
|
82
|
-
UIImage(systemName: "backward.end.fill",
|
|
83
|
-
withConfiguration: UIImage.SymbolConfiguration(pointSize: 28, weight: .medium))?
|
|
84
|
-
.withTintColor(.white, renderingMode: .alwaysOriginal),
|
|
85
|
-
for: .normal
|
|
86
|
-
)
|
|
87
|
-
previousButton.addTarget(self, action: #selector(previousTapped), for: .touchUpInside)
|
|
88
|
-
|
|
89
|
-
// Play/Pause Button
|
|
90
|
-
playPauseButton.setImage(
|
|
91
|
-
UIImage(systemName: "play.circle.fill",
|
|
92
|
-
withConfiguration: UIImage.SymbolConfiguration(pointSize: 44, weight: .medium))?
|
|
93
|
-
.withTintColor(.systemGreen, renderingMode: .alwaysOriginal),
|
|
94
|
-
for: .normal
|
|
95
|
-
)
|
|
96
|
-
playPauseButton.addTarget(self, action: #selector(playPauseTapped), for: .touchUpInside)
|
|
97
|
-
|
|
98
|
-
// Next Button
|
|
99
|
-
nextButton.setImage(
|
|
100
|
-
UIImage(systemName: "forward.end.fill",
|
|
101
|
-
withConfiguration: UIImage.SymbolConfiguration(pointSize: 28, weight: .medium))?
|
|
102
|
-
.withTintColor(.white, renderingMode: .alwaysOriginal),
|
|
103
|
-
for: .normal
|
|
104
|
-
)
|
|
105
|
-
nextButton.addTarget(self, action: #selector(nextTapped), for: .touchUpInside)
|
|
106
|
-
|
|
107
|
-
// Button Stack (horizontal)
|
|
108
|
-
buttonStack.axis = .horizontal
|
|
109
|
-
buttonStack.alignment = .center
|
|
110
|
-
buttonStack.distribution = .equalSpacing
|
|
111
|
-
buttonStack.spacing = 40
|
|
112
|
-
buttonStack.addArrangedSubview(previousButton)
|
|
113
|
-
buttonStack.addArrangedSubview(playPauseButton)
|
|
114
|
-
buttonStack.addArrangedSubview(nextButton)
|
|
115
|
-
|
|
116
69
|
// Main container stack (vertical)
|
|
117
70
|
containerStack.axis = .vertical
|
|
118
71
|
containerStack.alignment = .fill
|
|
@@ -139,14 +92,6 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
139
92
|
containerStack.addArrangedSubview(progressView)
|
|
140
93
|
containerStack.addArrangedSubview(timeStack)
|
|
141
94
|
|
|
142
|
-
// Spacer between time and buttons
|
|
143
|
-
let spacer3 = UIView()
|
|
144
|
-
spacer3.translatesAutoresizingMaskIntoConstraints = false
|
|
145
|
-
spacer3.heightAnchor.constraint(equalToConstant: 16).isActive = true
|
|
146
|
-
containerStack.addArrangedSubview(spacer3)
|
|
147
|
-
|
|
148
|
-
containerStack.addArrangedSubview(buttonStack)
|
|
149
|
-
|
|
150
95
|
view.addSubview(containerStack)
|
|
151
96
|
}
|
|
152
97
|
|
|
@@ -172,15 +117,6 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
172
117
|
func updatePlaybackState(isPlaying: Bool) {
|
|
173
118
|
statusLabel.text = isPlaying ? "OYNATILIYOR" : "DURAKLATILDI"
|
|
174
119
|
statusLabel.textColor = isPlaying ? UIColor.systemGreen : UIColor.systemGray
|
|
175
|
-
|
|
176
|
-
let iconName = isPlaying ? "pause.circle.fill" : "play.circle.fill"
|
|
177
|
-
let color: UIColor = isPlaying ? .systemOrange : .systemGreen
|
|
178
|
-
playPauseButton.setImage(
|
|
179
|
-
UIImage(systemName: iconName,
|
|
180
|
-
withConfiguration: UIImage.SymbolConfiguration(pointSize: 44, weight: .medium))?
|
|
181
|
-
.withTintColor(color, renderingMode: .alwaysOriginal),
|
|
182
|
-
for: .normal
|
|
183
|
-
)
|
|
184
120
|
}
|
|
185
121
|
|
|
186
122
|
func updateTime(elapsed: Double, duration: Double) {
|
|
@@ -202,17 +138,4 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
202
138
|
return String(format: "%d:%02d", mins, secs)
|
|
203
139
|
}
|
|
204
140
|
|
|
205
|
-
// MARK: - Button Actions
|
|
206
|
-
|
|
207
|
-
@objc private func previousTapped() {
|
|
208
|
-
onPreviousTrack?()
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
@objc private func playPauseTapped() {
|
|
212
|
-
onPlayPause?()
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
@objc private func nextTapped() {
|
|
216
|
-
onNextTrack?()
|
|
217
|
-
}
|
|
218
141
|
}
|