@neoskola/auto-play 0.3.11 → 0.3.12
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 = []
|
|
46
46
|
|
|
47
47
|
DispatchQueue.main.async { [weak self] in
|
|
48
48
|
guard let self = self else { return }
|
|
@@ -57,53 +57,6 @@ 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(.systemBlue, 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 playPauseColor: UIColor = isPlaying ? .systemOrange : .systemGreen
|
|
76
|
-
let playPauseImage = UIImage(systemName: playPauseIconName)?
|
|
77
|
-
.withTintColor(playPauseColor, renderingMode: .alwaysOriginal)
|
|
78
|
-
.resized(to: buttonSize)
|
|
79
|
-
let playPauseButton = CPMapButton(image: playPauseImage ?? UIImage()) { [weak owner] _ in
|
|
80
|
-
guard let owner = owner else { return }
|
|
81
|
-
DispatchQueue.main.async {
|
|
82
|
-
if owner.config.isPlaying {
|
|
83
|
-
owner.pauseAudio()
|
|
84
|
-
owner.config.onPause?()
|
|
85
|
-
} else {
|
|
86
|
-
owner.resumeAudio()
|
|
87
|
-
owner.config.onPlay?()
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Next track button
|
|
93
|
-
let nextImage = UIImage(systemName: "forward.end.fill")?
|
|
94
|
-
.withTintColor(.systemBlue, renderingMode: .alwaysOriginal)
|
|
95
|
-
.resized(to: buttonSize)
|
|
96
|
-
let nextButton = CPMapButton(image: nextImage ?? UIImage()) { [weak owner] _ in
|
|
97
|
-
owner?.config.onNextTrack?()
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return [prevButton, playPauseButton, nextButton]
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private func updateMapButtons() {
|
|
104
|
-
template.mapButtons = Self.buildMapButtons(isPlaying: config.isPlaying, owner: self)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
60
|
// MARK: - Custom View Injection
|
|
108
61
|
|
|
109
62
|
@MainActor
|
|
@@ -122,6 +75,26 @@ class NowPlayingTemplate: NSObject, AutoPlayTemplate, CPMapTemplateDelegate {
|
|
|
122
75
|
customVC.updateInfo(courseName: subtitleText, lessonName: titleText)
|
|
123
76
|
customVC.updatePlaybackState(isPlaying: config.isPlaying)
|
|
124
77
|
|
|
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
|
+
|
|
125
98
|
window.rootViewController = customVC
|
|
126
99
|
window.makeKeyAndVisible()
|
|
127
100
|
|
|
@@ -151,7 +124,6 @@ class NowPlayingTemplate: NSObject, AutoPlayTemplate, CPMapTemplateDelegate {
|
|
|
151
124
|
customVC.updateInfo(courseName: subtitleText, lessonName: titleText)
|
|
152
125
|
customVC.updatePlaybackState(isPlaying: config.isPlaying)
|
|
153
126
|
customVC.updateTime(elapsed: currentElapsedTime, duration: currentDuration)
|
|
154
|
-
updateMapButtons()
|
|
155
127
|
}
|
|
156
128
|
|
|
157
129
|
// MARK: - Native Audio Playback
|
|
@@ -2,7 +2,7 @@ import UIKit
|
|
|
2
2
|
|
|
3
3
|
class NeoSkolaNowPlayingViewController: UIViewController {
|
|
4
4
|
|
|
5
|
-
// MARK: - UI Elements
|
|
5
|
+
// MARK: - UI Elements
|
|
6
6
|
private let containerStack = UIStackView()
|
|
7
7
|
private let courseNameLabel = UILabel()
|
|
8
8
|
private let lessonNameLabel = UILabel()
|
|
@@ -12,6 +12,17 @@ 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
|
+
|
|
15
26
|
// MARK: - Lifecycle
|
|
16
27
|
|
|
17
28
|
override func viewDidLoad() {
|
|
@@ -66,6 +77,42 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
66
77
|
timeStack.addArrangedSubview(currentTimeLabel)
|
|
67
78
|
timeStack.addArrangedSubview(durationLabel)
|
|
68
79
|
|
|
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
|
+
|
|
69
116
|
// Main container stack (vertical)
|
|
70
117
|
containerStack.axis = .vertical
|
|
71
118
|
containerStack.alignment = .fill
|
|
@@ -92,6 +139,14 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
92
139
|
containerStack.addArrangedSubview(progressView)
|
|
93
140
|
containerStack.addArrangedSubview(timeStack)
|
|
94
141
|
|
|
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
|
+
|
|
95
150
|
view.addSubview(containerStack)
|
|
96
151
|
}
|
|
97
152
|
|
|
@@ -117,6 +172,15 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
117
172
|
func updatePlaybackState(isPlaying: Bool) {
|
|
118
173
|
statusLabel.text = isPlaying ? "OYNATILIYOR" : "DURAKLATILDI"
|
|
119
174
|
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
|
+
)
|
|
120
184
|
}
|
|
121
185
|
|
|
122
186
|
func updateTime(elapsed: Double, duration: Double) {
|
|
@@ -137,4 +201,18 @@ class NeoSkolaNowPlayingViewController: UIViewController {
|
|
|
137
201
|
let secs = Int(seconds) % 60
|
|
138
202
|
return String(format: "%d:%02d", mins, secs)
|
|
139
203
|
}
|
|
204
|
+
|
|
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
|
+
}
|
|
140
218
|
}
|