capacitor-plugin-playlist 0.1.20 → 0.1.24
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.
- package/android/src/main/java/org/dwbn/plugins/playlist/PlaylistPlugin.kt +2 -2
- package/android/src/main/java/org/dwbn/plugins/playlist/RmxAudioPlayer.java +1 -1
- package/android/src/main/java/org/dwbn/plugins/playlist/manager/PlaylistManager.kt +18 -0
- package/dist/docs.json +8 -26
- package/dist/esm/Constants.js.map +1 -1
- package/dist/esm/RmxAudioPlayer.d.ts +4 -10
- package/dist/esm/RmxAudioPlayer.js +19 -22
- package/dist/esm/RmxAudioPlayer.js.map +1 -1
- package/dist/esm/definitions.d.ts +9 -8
- package/dist/esm/definitions.js +0 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces.js +0 -1
- package/dist/esm/plugin.js +1 -0
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/web.d.ts +3 -3
- package/dist/esm/web.js +32 -27
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +47 -44
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +48 -45
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/AVBidirectionalQueuePlayer.swift +18 -4
- package/ios/Plugin/AudioTrack.swift +0 -1
- package/ios/Plugin/DispatchQueue.swift +3 -3
- package/ios/Plugin/Plugin.swift +3 -3
- package/ios/Plugin/RmxAudioPlayer.swift +41 -42
- package/package.json +1 -1
- package/android/.gitignore +0 -1
- package/android/.npmignore +0 -1
|
@@ -12,7 +12,7 @@ public extension DispatchQueue {
|
|
|
12
12
|
- action: The closure to be executed
|
|
13
13
|
Delays a closure execution and ensures no other executions are made during deadline
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
func throttle(deadline: DispatchTime, context: AnyHashable? = nil, action: @escaping () -> Void) {
|
|
16
16
|
let worker = DispatchWorkItem {
|
|
17
17
|
defer { throttleWorkItems.removeValue(forKey: context ?? nilContext) }
|
|
18
18
|
action()
|
|
@@ -31,7 +31,7 @@ public extension DispatchQueue {
|
|
|
31
31
|
- action: The closure to be executed
|
|
32
32
|
Executes a closure and ensures no other executions will be made during the interval.
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
func debounce(interval: Double, context: AnyHashable? = nil, action: @escaping () -> Void) {
|
|
35
35
|
if let last = lastDebounceCallTimes[context ?? nilContext], last + interval > .now() {
|
|
36
36
|
return
|
|
37
37
|
}
|
|
@@ -44,4 +44,4 @@ public extension DispatchQueue {
|
|
|
44
44
|
lastDebounceCallTimes.removeValue(forKey: context ?? nilContext)
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|
package/ios/Plugin/Plugin.swift
CHANGED
|
@@ -53,11 +53,11 @@ public class PlaylistPlugin: CAPPlugin, StatusUpdater {
|
|
|
53
53
|
}
|
|
54
54
|
@objc func removeItem(_ call: CAPPluginCall) {
|
|
55
55
|
do {
|
|
56
|
-
if let id = call.getString("
|
|
56
|
+
if let id = call.getString("id"){
|
|
57
57
|
try audioPlayerImpl.removeItem(id)
|
|
58
58
|
return
|
|
59
59
|
}
|
|
60
|
-
guard let index = call.getString("
|
|
60
|
+
guard let index = call.getString("index") else {
|
|
61
61
|
call.reject("Cannot remove")
|
|
62
62
|
return
|
|
63
63
|
}
|
|
@@ -152,7 +152,7 @@ public class PlaylistPlugin: CAPPlugin, StatusUpdater {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
do {
|
|
155
|
-
try audioPlayerImpl.selectTrack(
|
|
155
|
+
try audioPlayerImpl.selectTrack(id: id)
|
|
156
156
|
call.resolve();
|
|
157
157
|
}
|
|
158
158
|
catch let message {
|
|
@@ -29,6 +29,8 @@ final class RmxAudioPlayer: NSObject {
|
|
|
29
29
|
|
|
30
30
|
private let avQueuePlayer = AVBidirectionalQueuePlayer(items: [])
|
|
31
31
|
|
|
32
|
+
private var lastTrackId: String? = nil
|
|
33
|
+
private var lastRate: Float? = nil
|
|
32
34
|
override init() {
|
|
33
35
|
super.init()
|
|
34
36
|
|
|
@@ -140,7 +142,7 @@ final class RmxAudioPlayer: NSObject {
|
|
|
140
142
|
|
|
141
143
|
func clearAllItems() {
|
|
142
144
|
print("RmxAudioPlayer.execute=clearAllItems")
|
|
143
|
-
removeAllTracks(
|
|
145
|
+
removeAllTracks()
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
func playTrack(index: Int, positionTime: Float?) throws {
|
|
@@ -205,11 +207,11 @@ final class RmxAudioPlayer: NSObject {
|
|
|
205
207
|
avQueuePlayer.setCurrentIndex(index)
|
|
206
208
|
}
|
|
207
209
|
|
|
208
|
-
func selectTrack(
|
|
210
|
+
func selectTrack(id: String) throws {
|
|
209
211
|
guard !avQueuePlayer.queuedAudioTracks.isEmpty else {
|
|
210
212
|
throw "Queue is Empty"
|
|
211
213
|
}
|
|
212
|
-
let result = findTrack(byId:
|
|
214
|
+
let result = findTrack(byId: id)
|
|
213
215
|
let idx = (result?["index"] as? NSNumber)?.intValue ?? 0
|
|
214
216
|
|
|
215
217
|
if idx >= 0 {
|
|
@@ -232,7 +234,7 @@ final class RmxAudioPlayer: NSObject {
|
|
|
232
234
|
let track = result?["track"] as? AudioTrack
|
|
233
235
|
|
|
234
236
|
guard idx >= 0 else {
|
|
235
|
-
throw "Could not find
|
|
237
|
+
throw "Could not find track by id" + id
|
|
236
238
|
}
|
|
237
239
|
// AudioTrack* item = [self avQueuePlayer].itemsForPlayer[idx];
|
|
238
240
|
removeTrackObservers(track)
|
|
@@ -385,7 +387,7 @@ final class RmxAudioPlayer: NSObject {
|
|
|
385
387
|
}
|
|
386
388
|
}
|
|
387
389
|
|
|
388
|
-
func removeAllTracks(
|
|
390
|
+
func removeAllTracks() {
|
|
389
391
|
for item in avQueuePlayer.queuedAudioTracks {
|
|
390
392
|
removeTrackObservers(item)
|
|
391
393
|
}
|
|
@@ -393,15 +395,6 @@ final class RmxAudioPlayer: NSObject {
|
|
|
393
395
|
avQueuePlayer.removeAllItems()
|
|
394
396
|
wasPlayingInterrupted = false
|
|
395
397
|
|
|
396
|
-
print("RmxAudioPlayer, removeAllTracks, ==> RMXSTATUS_PLAYLIST_CLEARED")
|
|
397
|
-
onStatus(.rmxstatus_PLAYLIST_CLEARED, trackId: "INVALID", param: nil)
|
|
398
|
-
|
|
399
|
-
// a.t.m there's no way for this to be triggered from within the plugin,
|
|
400
|
-
// but it might get added at some point.
|
|
401
|
-
if isCommand {
|
|
402
|
-
let action = "music-controls-clear"
|
|
403
|
-
print("\(action)")
|
|
404
|
-
}
|
|
405
398
|
}
|
|
406
399
|
|
|
407
400
|
// MARK: - remote control events
|
|
@@ -454,7 +447,6 @@ final class RmxAudioPlayer: NSObject {
|
|
|
454
447
|
let trackStatus = getStatusItem(playerItem)
|
|
455
448
|
|
|
456
449
|
onStatus(.rmxstatus_STALLED, trackId: playerItem?.trackId, param: trackStatus)
|
|
457
|
-
onStatus(.rmxstatus_PAUSE, trackId: playerItem?.trackId, param: trackStatus)
|
|
458
450
|
}
|
|
459
451
|
|
|
460
452
|
@objc func playerItemDidReachEnd(_ notification: Notification?) {
|
|
@@ -528,31 +520,37 @@ final class RmxAudioPlayer: NSObject {
|
|
|
528
520
|
}
|
|
529
521
|
|
|
530
522
|
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
print("observing \(String(describing: change))")
|
|
523
|
+
guard let change = change else {
|
|
524
|
+
return
|
|
534
525
|
}
|
|
535
526
|
|
|
536
527
|
switch keyPath {
|
|
537
528
|
case "currentItem":
|
|
529
|
+
// only fire on real change!
|
|
538
530
|
let player = object as? AVBidirectionalQueuePlayer
|
|
539
531
|
let playerItem = player?.currentAudioTrack
|
|
532
|
+
guard lastTrackId != playerItem?.trackId else {
|
|
533
|
+
return // todo should call super instead or?
|
|
534
|
+
}
|
|
535
|
+
lastTrackId = playerItem?.trackId
|
|
540
536
|
handleCurrentItemChanged(playerItem)
|
|
541
537
|
case "rate":
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
538
|
+
guard lastRate != change[.newKey] as? Float else {
|
|
539
|
+
return // todo should call super instead or?
|
|
540
|
+
}
|
|
541
|
+
self.lastRate = change[.newKey] as? Float
|
|
542
|
+
let player = object as? AVBidirectionalQueuePlayer
|
|
543
|
+
|
|
544
|
+
guard let playerItem = player?.currentAudioTrack else { return }
|
|
546
545
|
|
|
547
|
-
|
|
548
|
-
|
|
546
|
+
let trackStatus = getStatusItem(playerItem)
|
|
547
|
+
print("Playback rate changed: \(String(describing: change[.newKey])), is playing: \(player?.isPlaying ?? false)")
|
|
549
548
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
})
|
|
549
|
+
if player?.isPlaying ?? false {
|
|
550
|
+
onStatus(.rmxstatus_PLAYING, trackId: playerItem.trackId, param: trackStatus)
|
|
551
|
+
} else {
|
|
552
|
+
onStatus(.rmxstatus_PAUSE, trackId: playerItem.trackId, param: trackStatus)
|
|
553
|
+
}
|
|
556
554
|
case "status":
|
|
557
555
|
DispatchQueue.main.debounce(interval: 0.2, context: self, action: { [self] in
|
|
558
556
|
let playerItem = object as? AudioTrack
|
|
@@ -562,10 +560,15 @@ final class RmxAudioPlayer: NSObject {
|
|
|
562
560
|
DispatchQueue.main.debounce(interval: 0.2, context: self, action: { [self] in
|
|
563
561
|
let player = object as? AVBidirectionalQueuePlayer
|
|
564
562
|
|
|
565
|
-
guard let playerItem = player?.currentAudioTrack else {
|
|
563
|
+
guard let playerItem = player?.currentAudioTrack else {
|
|
564
|
+
return
|
|
565
|
+
}
|
|
566
|
+
guard lastTrackId != playerItem.trackId else {
|
|
567
|
+
return // todo should call super instead or?
|
|
568
|
+
}
|
|
566
569
|
|
|
567
570
|
let trackStatus = getStatusItem(playerItem)
|
|
568
|
-
print("
|
|
571
|
+
print("TCSPlayback rate changed: \(String(describing: change[.newKey])), is playing: \(player?.isPlaying ?? false)")
|
|
569
572
|
|
|
570
573
|
if player?.timeControlStatus == .playing {
|
|
571
574
|
onStatus(.rmxstatus_PLAYING, trackId: playerItem.trackId, param: trackStatus)
|
|
@@ -620,19 +623,18 @@ final class RmxAudioPlayer: NSObject {
|
|
|
620
623
|
updatedNowPlayingInfo![MPMediaItemPropertyArtwork] = mediaItemArtwork
|
|
621
624
|
}
|
|
622
625
|
}
|
|
623
|
-
updatedNowPlayingInfo![MPMediaItemPropertyPlaybackDuration] =
|
|
624
|
-
updatedNowPlayingInfo![MPNowPlayingInfoPropertyElapsedPlaybackTime] =
|
|
625
|
-
updatedNowPlayingInfo![MPNowPlayingInfoPropertyPlaybackRate] =
|
|
626
|
+
updatedNowPlayingInfo![MPMediaItemPropertyPlaybackDuration] = duration ?? 0.0
|
|
627
|
+
updatedNowPlayingInfo![MPNowPlayingInfoPropertyElapsedPlaybackTime] = currentTime ?? 0.0
|
|
628
|
+
updatedNowPlayingInfo![MPNowPlayingInfoPropertyPlaybackRate] = 1.0
|
|
626
629
|
|
|
627
630
|
MPNowPlayingInfoCenter.default().nowPlayingInfo = updatedNowPlayingInfo
|
|
628
|
-
|
|
631
|
+
|
|
629
632
|
let commandCenter = MPRemoteCommandCenter.shared()
|
|
630
633
|
commandCenter.nextTrackCommand.isEnabled = !avQueuePlayer.isAtEnd
|
|
631
634
|
commandCenter.previousTrackCommand.isEnabled = !avQueuePlayer.isAtBeginning
|
|
632
635
|
}
|
|
633
636
|
|
|
634
637
|
func createCoverArtwork(_ coverUriOrNil: String?) -> MPMediaItemArtwork? {
|
|
635
|
-
print("Creating cover art : \(String(describing: coverUriOrNil))")
|
|
636
638
|
guard let coverUri = coverUriOrNil else {
|
|
637
639
|
return nil
|
|
638
640
|
}
|
|
@@ -654,9 +656,7 @@ final class RmxAudioPlayer: NSObject {
|
|
|
654
656
|
}
|
|
655
657
|
|
|
656
658
|
if isCoverImageValid(coverImage) {
|
|
657
|
-
print("valid cover image \(String(describing: coverImage)) size \(coverImage!.size)")
|
|
658
659
|
return MPMediaItemArtwork.init(boundsSize: coverImage!.size, requestHandler: { (size) -> UIImage in
|
|
659
|
-
print("inted cover image \(String(describing: coverImage)) size \(coverImage!.size)")
|
|
660
660
|
return coverImage!
|
|
661
661
|
})
|
|
662
662
|
}
|
|
@@ -850,7 +850,7 @@ final class RmxAudioPlayer: NSObject {
|
|
|
850
850
|
}
|
|
851
851
|
|
|
852
852
|
if avQueuePlayer.currentItem == currentItem {
|
|
853
|
-
if avQueuePlayer.rate != 0 {
|
|
853
|
+
if avQueuePlayer.rate != 0.0 {
|
|
854
854
|
status = "playing"
|
|
855
855
|
|
|
856
856
|
if position <= 0 && (bufferInfo?["bufferPercent"] as? NSNumber)?.floatValue ?? 0.0 == 0.0 {
|
|
@@ -980,7 +980,6 @@ final class RmxAudioPlayer: NSObject {
|
|
|
980
980
|
listener.addObserver(self, selector: #selector(itemStalledPlaying(_:)), name: .AVPlayerItemPlaybackStalled, object: playerItem)
|
|
981
981
|
|
|
982
982
|
onStatus(.rmxstatus_ITEM_ADDED, trackId: playerItem?.trackId, param: playerItem?.toDict())
|
|
983
|
-
onStatus(.rmxstatus_LOADING, trackId: playerItem?.trackId, param: nil)
|
|
984
983
|
}
|
|
985
984
|
|
|
986
985
|
@objc func queueCleared(_ notification: Notification?) {
|
|
@@ -1093,7 +1092,7 @@ final class RmxAudioPlayer: NSObject {
|
|
|
1093
1092
|
avQueuePlayer.removeObserver(self as NSObject, forKeyPath: "timeControlStatus")
|
|
1094
1093
|
deregisterMusicControlsEventListener()
|
|
1095
1094
|
|
|
1096
|
-
removeAllTracks(
|
|
1095
|
+
removeAllTracks()
|
|
1097
1096
|
|
|
1098
1097
|
playbackTimeObserver = nil
|
|
1099
1098
|
isWaitingToStartPlayback = false
|
package/package.json
CHANGED
package/android/.gitignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/build
|
package/android/.npmignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/build
|