@neoskola/auto-play 0.3.12 → 0.3.13
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,47 @@ class NowPlayingTemplate: NSObject, AutoPlayTemplate, CPMapTemplateDelegate {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
// MARK: - CPMapButton Controls (transparent touch handlers)
|
|
61
|
+
|
|
62
|
+
private static func buildMapButtons(isPlaying: Bool, owner: NowPlayingTemplate) -> [CPMapButton] {
|
|
63
|
+
// 1x1 transparent image for invisible buttons
|
|
64
|
+
let renderer = UIGraphicsImageRenderer(size: CGSize(width: 1, height: 1))
|
|
65
|
+
let clearImage = renderer.image { ctx in
|
|
66
|
+
UIColor.clear.setFill()
|
|
67
|
+
ctx.fill(CGRect(x: 0, y: 0, width: 1, height: 1))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Previous track button
|
|
71
|
+
let prevButton = CPMapButton(image: clearImage) { [weak owner] _ in
|
|
72
|
+
owner?.config.onPreviousTrack?()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Play/Pause button
|
|
76
|
+
let playPauseButton = CPMapButton(image: clearImage) { [weak owner] _ in
|
|
77
|
+
guard let owner = owner else { return }
|
|
78
|
+
DispatchQueue.main.async {
|
|
79
|
+
if owner.config.isPlaying {
|
|
80
|
+
owner.pauseAudio()
|
|
81
|
+
owner.config.onPause?()
|
|
82
|
+
} else {
|
|
83
|
+
owner.resumeAudio()
|
|
84
|
+
owner.config.onPlay?()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Next track button
|
|
90
|
+
let nextButton = CPMapButton(image: clearImage) { [weak owner] _ in
|
|
91
|
+
owner?.config.onNextTrack?()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return [prevButton, playPauseButton, nextButton]
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private func updateMapButtons() {
|
|
98
|
+
template.mapButtons = Self.buildMapButtons(isPlaying: config.isPlaying, owner: self)
|
|
99
|
+
}
|
|
100
|
+
|
|
60
101
|
// MARK: - Custom View Injection
|
|
61
102
|
|
|
62
103
|
@MainActor
|
|
@@ -75,26 +116,6 @@ class NowPlayingTemplate: NSObject, AutoPlayTemplate, CPMapTemplateDelegate {
|
|
|
75
116
|
customVC.updateInfo(courseName: subtitleText, lessonName: titleText)
|
|
76
117
|
customVC.updatePlaybackState(isPlaying: config.isPlaying)
|
|
77
118
|
|
|
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
119
|
window.rootViewController = customVC
|
|
99
120
|
window.makeKeyAndVisible()
|
|
100
121
|
|
|
@@ -124,6 +145,7 @@ class NowPlayingTemplate: NSObject, AutoPlayTemplate, CPMapTemplateDelegate {
|
|
|
124
145
|
customVC.updateInfo(courseName: subtitleText, lessonName: titleText)
|
|
125
146
|
customVC.updatePlaybackState(isPlaying: config.isPlaying)
|
|
126
147
|
customVC.updateTime(elapsed: currentElapsedTime, duration: currentDuration)
|
|
148
|
+
updateMapButtons()
|
|
127
149
|
}
|
|
128
150
|
|
|
129
151
|
// MARK: - Native Audio Playback
|
|
@@ -12,16 +12,11 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
12
12
|
private let durationLabel = UILabel()
|
|
13
13
|
private let timeStack = UIStackView()
|
|
14
14
|
|
|
15
|
-
// MARK: - Button Controls
|
|
15
|
+
// MARK: - Button Controls (visual only, touch handled by CPMapButton)
|
|
16
16
|
private let buttonStack = UIStackView()
|
|
17
|
-
private let previousButton = UIButton(type: .
|
|
18
|
-
private let playPauseButton = UIButton(type: .
|
|
19
|
-
private let nextButton = UIButton(type: .
|
|
20
|
-
|
|
21
|
-
// MARK: - Callbacks
|
|
22
|
-
var onPreviousTrack: (() -> Void)?
|
|
23
|
-
var onPlayPause: (() -> Void)?
|
|
24
|
-
var onNextTrack: (() -> Void)?
|
|
17
|
+
private let previousButton = UIButton(type: .custom)
|
|
18
|
+
private let playPauseButton = UIButton(type: .custom)
|
|
19
|
+
private let nextButton = UIButton(type: .custom)
|
|
25
20
|
|
|
26
21
|
// MARK: - Lifecycle
|
|
27
22
|
|
|
@@ -84,16 +79,18 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
84
79
|
.withTintColor(.white, renderingMode: .alwaysOriginal),
|
|
85
80
|
for: .normal
|
|
86
81
|
)
|
|
87
|
-
previousButton.
|
|
82
|
+
previousButton.backgroundColor = .clear
|
|
83
|
+
previousButton.isUserInteractionEnabled = false
|
|
88
84
|
|
|
89
85
|
// Play/Pause Button
|
|
90
86
|
playPauseButton.setImage(
|
|
91
87
|
UIImage(systemName: "play.circle.fill",
|
|
92
88
|
withConfiguration: UIImage.SymbolConfiguration(pointSize: 44, weight: .medium))?
|
|
93
|
-
.withTintColor(.
|
|
89
|
+
.withTintColor(.white, renderingMode: .alwaysOriginal),
|
|
94
90
|
for: .normal
|
|
95
91
|
)
|
|
96
|
-
playPauseButton.
|
|
92
|
+
playPauseButton.backgroundColor = .clear
|
|
93
|
+
playPauseButton.isUserInteractionEnabled = false
|
|
97
94
|
|
|
98
95
|
// Next Button
|
|
99
96
|
nextButton.setImage(
|
|
@@ -102,7 +99,8 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
102
99
|
.withTintColor(.white, renderingMode: .alwaysOriginal),
|
|
103
100
|
for: .normal
|
|
104
101
|
)
|
|
105
|
-
nextButton.
|
|
102
|
+
nextButton.backgroundColor = .clear
|
|
103
|
+
nextButton.isUserInteractionEnabled = false
|
|
106
104
|
|
|
107
105
|
// Button Stack (horizontal)
|
|
108
106
|
buttonStack.axis = .horizontal
|
|
@@ -174,11 +172,10 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
174
172
|
statusLabel.textColor = isPlaying ? UIColor.systemGreen : UIColor.systemGray
|
|
175
173
|
|
|
176
174
|
let iconName = isPlaying ? "pause.circle.fill" : "play.circle.fill"
|
|
177
|
-
let color: UIColor = isPlaying ? .systemOrange : .systemGreen
|
|
178
175
|
playPauseButton.setImage(
|
|
179
176
|
UIImage(systemName: iconName,
|
|
180
177
|
withConfiguration: UIImage.SymbolConfiguration(pointSize: 44, weight: .medium))?
|
|
181
|
-
.withTintColor(
|
|
178
|
+
.withTintColor(.white, renderingMode: .alwaysOriginal),
|
|
182
179
|
for: .normal
|
|
183
180
|
)
|
|
184
181
|
}
|
|
@@ -202,17 +199,4 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
202
199
|
return String(format: "%d:%02d", mins, secs)
|
|
203
200
|
}
|
|
204
201
|
|
|
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
202
|
}
|