capacitor-plugin-playlist 0.1.19 → 0.1.23

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.
Files changed (33) hide show
  1. package/android/src/main/java/org/dwbn/plugins/playlist/PlaylistPlugin.kt +4 -8
  2. package/android/src/main/java/org/dwbn/plugins/playlist/RmxAudioPlayer.java +397 -385
  3. package/android/src/main/java/org/dwbn/plugins/playlist/manager/PlaylistManager.kt +17 -12
  4. package/android/src/main/java/org/dwbn/plugins/playlist/notification/PlaylistNotificationProvider.kt +5 -1
  5. package/android/src/main/java/org/dwbn/plugins/playlist/service/MediaService.kt +1 -2
  6. package/dist/docs.json +3 -21
  7. package/dist/esm/Constants.js.map +1 -1
  8. package/dist/esm/RmxAudioPlayer.d.ts +4 -10
  9. package/dist/esm/RmxAudioPlayer.js +19 -22
  10. package/dist/esm/RmxAudioPlayer.js.map +1 -1
  11. package/dist/esm/definitions.d.ts +5 -4
  12. package/dist/esm/index.d.ts +1 -1
  13. package/dist/esm/index.js +1 -1
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/plugin.js +1 -0
  16. package/dist/esm/plugin.js.map +1 -1
  17. package/dist/esm/utils.d.ts +1 -1
  18. package/dist/esm/utils.js.map +1 -1
  19. package/dist/esm/web.d.ts +3 -3
  20. package/dist/esm/web.js +32 -27
  21. package/dist/esm/web.js.map +1 -1
  22. package/dist/plugin.cjs.js +47 -44
  23. package/dist/plugin.cjs.js.map +1 -1
  24. package/dist/plugin.js +48 -45
  25. package/dist/plugin.js.map +1 -1
  26. package/ios/Plugin/AVBidirectionalQueuePlayer.swift +18 -4
  27. package/ios/Plugin/AudioTrack.swift +0 -1
  28. package/ios/Plugin/DispatchQueue.swift +3 -3
  29. package/ios/Plugin/RmxAudioPlayer.swift +38 -39
  30. package/package.json +1 -1
  31. package/android/.gitignore +0 -1
  32. package/android/.npmignore +0 -1
  33. package/ios/.DS_Store +0 -0
@@ -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
- public func throttle(deadline: DispatchTime, context: AnyHashable? = nil, action: @escaping () -> Void) {
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
- public func debounce(interval: Double, context: AnyHashable? = nil, action: @escaping () -> Void) {
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
+ }
@@ -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(false)
145
+ removeAllTracks()
144
146
  }
145
147
 
146
148
  func playTrack(index: Int, positionTime: Float?) throws {
@@ -385,7 +387,7 @@ final class RmxAudioPlayer: NSObject {
385
387
  }
386
388
  }
387
389
 
388
- func removeAllTracks(_ isCommand: Bool) {
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
- if keyPath != "loadedTimeRanges" {
532
- print("observing \(String(describing: keyPath))")
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
- DispatchQueue.main.debounce(interval: 0.2, context: self, action: { [self] in
543
- let player = object as? AVBidirectionalQueuePlayer
544
-
545
- guard let playerItem = player?.currentAudioTrack else { return }
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
- let trackStatus = getStatusItem(playerItem)
548
- print("Playback rate changed: \(1), is playing: \(player?.isPlaying ?? false)")
546
+ let trackStatus = getStatusItem(playerItem)
547
+ print("Playback rate changed: \(String(describing: change[.newKey])), is playing: \(player?.isPlaying ?? false)")
549
548
 
550
- if player?.isPlaying ?? false {
551
- onStatus(.rmxstatus_PLAYING, trackId: playerItem.trackId, param: trackStatus)
552
- } else {
553
- onStatus(.rmxstatus_PAUSE, trackId: playerItem.trackId, param: trackStatus)
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 { return }
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("Playback rate changed: \(1), is playing: \(player?.isPlaying ?? false)")
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] = NSNumber(value: duration ?? 0.0)
624
- updatedNowPlayingInfo![MPNowPlayingInfoPropertyElapsedPlaybackTime] = NSNumber(value: currentTime ?? 0.0)
625
- updatedNowPlayingInfo![MPNowPlayingInfoPropertyPlaybackRate] = NSNumber(value: 1.0)
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
- print("noplaying \(String(describing: updatedNowPlayingInfo))")
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(false)
1095
+ removeAllTracks()
1097
1096
 
1098
1097
  playbackTimeObserver = nil
1099
1098
  isWaitingToStartPlayback = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-plugin-playlist",
3
- "version": "0.1.19",
3
+ "version": "0.1.23",
4
4
  "description": "Playlist ",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -1 +0,0 @@
1
- /build
@@ -1 +0,0 @@
1
- /build
package/ios/.DS_Store DELETED
Binary file