capacitor-plugin-playlist 0.1.33 → 0.1.34
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.
|
@@ -34,23 +34,23 @@ let AVBidirectionalQueueCleared = "AVBidirectionalQueuePlayer.Cleared"
|
|
|
34
34
|
|
|
35
35
|
class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
36
36
|
var queuedAudioTracks: [AudioTrack] = []
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
var isPlaying: Bool {
|
|
39
39
|
timeControlStatus == .playing
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
var isAtBeginning: Bool {
|
|
43
43
|
// This function simply returns whether or not the AVBidirectionalQueuePlayer is at the first item. This is
|
|
44
44
|
// useful for implementing custom behavior if the user tries to play a previous item at the start of
|
|
45
45
|
// the queue (such as restarting the item).
|
|
46
46
|
currentIndex() == 0
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
var isAtEnd: Bool {
|
|
50
50
|
guard let currentIndex = currentIndex() else { return true }
|
|
51
51
|
return currentIndex >= (queuedAudioTracks.endIndex - 1)
|
|
52
|
-
}
|
|
53
|
-
|
|
52
|
+
}
|
|
53
|
+
|
|
54
54
|
var currentAudioTrack: AudioTrack? { currentItem as? AudioTrack }
|
|
55
55
|
|
|
56
56
|
override init() {
|
|
@@ -61,9 +61,9 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
61
61
|
super.init(items: items)
|
|
62
62
|
queuedAudioTracks = items
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
|
|
65
65
|
// Two methods need to be added to the AVQueuePlayer: one which will play the last song in the queue, and one which will return if the queue is at the beginning (in case the user wishes to implement special behavior when a queue is at its first item, such as restarting a song). A getIndex method to return the current index is also provided.
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
// NEW METHODS
|
|
68
68
|
|
|
69
69
|
func playPreviousItem() {
|
|
@@ -129,11 +129,11 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
129
129
|
setCurrentIndex(0)
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
|
|
133
133
|
func setCurrentIndex(_ currentIndex: Int) {
|
|
134
134
|
setCurrentIndex(currentIndex, completionHandler: { _ in })
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
|
|
137
137
|
func setCurrentIndex(_ newCurrentIndex: Int, completionHandler: @escaping (Bool) -> Void) {
|
|
138
138
|
let currentrate = rate
|
|
139
139
|
if currentrate > 0 {
|
|
@@ -153,7 +153,7 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
153
153
|
// Not a typo; see above comment
|
|
154
154
|
seek(to: .zero, toleranceBefore: .zero, toleranceAfter: .zero, completionHandler: completionHandler)
|
|
155
155
|
}
|
|
156
|
-
|
|
156
|
+
|
|
157
157
|
func replaceAllItems(with items: [AudioTrack]) {
|
|
158
158
|
print("AVBI, replaceAllItems")
|
|
159
159
|
removeAllItemsSilently()
|
|
@@ -164,7 +164,7 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
164
164
|
for item in items {
|
|
165
165
|
insert(item, after: nil)
|
|
166
166
|
}
|
|
167
|
-
|
|
167
|
+
|
|
168
168
|
let center = NotificationCenter.default
|
|
169
169
|
center.post(name: NSNotification.Name(AVBidirectionalQueueAddedAllItems), object: self, userInfo: [
|
|
170
170
|
"items": items
|
|
@@ -178,7 +178,7 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
178
178
|
– removeAllItems to update the now playing index
|
|
179
179
|
– removeItem: to update the now playing index
|
|
180
180
|
*/
|
|
181
|
-
|
|
181
|
+
|
|
182
182
|
func currentIndex() -> Int? {
|
|
183
183
|
guard let currentAudioTrack = currentAudioTrack else { return nil }
|
|
184
184
|
return queuedAudioTracks.firstIndex(of: currentAudioTrack)
|
|
@@ -200,10 +200,10 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
200
200
|
print("removeAllItems")
|
|
201
201
|
super.removeAllItems()
|
|
202
202
|
queuedAudioTracks.removeAll()
|
|
203
|
-
|
|
203
|
+
|
|
204
204
|
NotificationCenter.default.post(name: NSNotification.Name(AVBidirectionalQueueCleared), object: self, userInfo: nil)
|
|
205
205
|
}
|
|
206
|
-
|
|
206
|
+
|
|
207
207
|
func removeAllItemsSilently() {
|
|
208
208
|
print("removeAllItemsSilently")
|
|
209
209
|
super.removeAllItems()
|
|
@@ -230,7 +230,7 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
230
230
|
// This method calls the superclass to add the new item to the AVQueuePlayer, then adds that item to the
|
|
231
231
|
// proper location in the itemsForPlayer array and increments the nowPlayingIndex if necessary.
|
|
232
232
|
super.insert(item, after: afterItem)
|
|
233
|
-
|
|
233
|
+
|
|
234
234
|
if afterItem != nil && queuedAudioTracks.contains(afterItem!) {
|
|
235
235
|
// AfterItem is non-nil
|
|
236
236
|
if (queuedAudioTracks.firstIndex(of: afterItem!) ?? NSNotFound) < (queuedAudioTracks.count - 1) {
|