capacitor-plugin-playlist 0.1.32 → 0.1.33
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/local.properties +8 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/manager/PlaylistManager.kt +6 -8
- package/dist/esm/interfaces.d.ts +6 -0
- package/ios/Plugin/AVBidirectionalQueuePlayer.swift +7 -9
- package/ios/Plugin/RmxAudioPlayer.swift +27 -37
- package/package.json +1 -1
- package/android/.gitignore +0 -1
- package/android/.npmignore +0 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
## This file must *NOT* be checked into Version Control Systems,
|
|
2
|
+
# as it contains information specific to your local configuration.
|
|
3
|
+
#
|
|
4
|
+
# Location of the SDK. This is only used by Gradle.
|
|
5
|
+
# For customization when using a Version Control System, please read the
|
|
6
|
+
# header note.
|
|
7
|
+
#Sat Jan 15 16:11:50 CET 2022
|
|
8
|
+
sdk.dir=/home/phiamo/Android/Sdk
|
|
@@ -104,14 +104,12 @@ class PlaylistManager(application: Application) :
|
|
|
104
104
|
currentPosition = 0
|
|
105
105
|
// If the options said to start from a specific position, do so.
|
|
106
106
|
var seekStart: Long = 0
|
|
107
|
-
if (options.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
seekStart = progress.position
|
|
114
|
-
}
|
|
107
|
+
if (options.playFromPosition > 0) {
|
|
108
|
+
seekStart = options.playFromPosition
|
|
109
|
+
} else if (options.retainPosition) {
|
|
110
|
+
val progress = currentProgress
|
|
111
|
+
if (progress != null) {
|
|
112
|
+
seekStart = progress.position
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
115
|
|
package/dist/esm/interfaces.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ export interface PlaylistStatusChangeCallbackArg {
|
|
|
15
15
|
action: string;
|
|
16
16
|
status: OnStatusCallbackData;
|
|
17
17
|
}
|
|
18
|
+
export interface AudioTrackOptions {
|
|
19
|
+
playFromPosition: number;
|
|
20
|
+
startPaused: boolean;
|
|
21
|
+
retainPosition: boolean;
|
|
22
|
+
playFromId: string;
|
|
23
|
+
}
|
|
18
24
|
/**
|
|
19
25
|
* Options governing the overall behavior of the audio player plugin
|
|
20
26
|
*/
|
|
@@ -45,11 +45,11 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
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
|
-
}
|
|
52
|
+
}*/
|
|
53
53
|
|
|
54
54
|
var currentAudioTrack: AudioTrack? { currentItem as? AudioTrack }
|
|
55
55
|
|
|
@@ -123,7 +123,7 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
open override func advanceToNextItem() {
|
|
126
|
-
if currentIndex() == nil || currentIndex()! <
|
|
126
|
+
if currentIndex() == nil || currentIndex()! < queuedAudioTracks.count - 1{
|
|
127
127
|
super.advanceToNextItem();
|
|
128
128
|
} else {
|
|
129
129
|
setCurrentIndex(0)
|
|
@@ -135,9 +135,6 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
func setCurrentIndex(_ newCurrentIndex: Int, completionHandler: @escaping (Bool) -> Void) {
|
|
138
|
-
// NSUInteger tempNowPlayingIndex = [_itemsForPlayer indexOfObject: self.currentItem];
|
|
139
|
-
|
|
140
|
-
// if (tempNowPlayingIndex != NSNotFound){
|
|
141
138
|
let currentrate = rate
|
|
142
139
|
if currentrate > 0 {
|
|
143
140
|
pause()
|
|
@@ -155,7 +152,6 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
155
152
|
}
|
|
156
153
|
// Not a typo; see above comment
|
|
157
154
|
seek(to: .zero, toleranceBefore: .zero, toleranceAfter: .zero, completionHandler: completionHandler)
|
|
158
|
-
// }
|
|
159
155
|
}
|
|
160
156
|
|
|
161
157
|
func replaceAllItems(with items: [AudioTrack]) {
|
|
@@ -189,6 +185,8 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
189
185
|
}
|
|
190
186
|
|
|
191
187
|
// OVERRIDDEN AVQUEUEPLAYER METHODS
|
|
188
|
+
/*
|
|
189
|
+
resolving #9 and 11 and taking this out remove code after stabilize
|
|
192
190
|
override func play() {
|
|
193
191
|
if isAtEnd {
|
|
194
192
|
// we could add a flag here to indicate looping
|
|
@@ -196,7 +194,7 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
196
194
|
}
|
|
197
195
|
|
|
198
196
|
super.play()
|
|
199
|
-
}
|
|
197
|
+
}*/
|
|
200
198
|
// This does the same thing as the normal AVQueuePlayer removeAllItems, but clears our collection copy
|
|
201
199
|
override func removeAllItems() {
|
|
202
200
|
print("removeAllItems")
|
|
@@ -235,7 +233,7 @@ class AVBidirectionalQueuePlayer: AVQueuePlayer {
|
|
|
235
233
|
|
|
236
234
|
if afterItem != nil && queuedAudioTracks.contains(afterItem!) {
|
|
237
235
|
// AfterItem is non-nil
|
|
238
|
-
if (queuedAudioTracks.firstIndex(of: afterItem!) ?? NSNotFound) < (queuedAudioTracks.count
|
|
236
|
+
if (queuedAudioTracks.firstIndex(of: afterItem!) ?? NSNotFound) < (queuedAudioTracks.count - 1) {
|
|
239
237
|
queuedAudioTracks.insert(item, at: (queuedAudioTracks.firstIndex(of: afterItem!) ?? NSNotFound) + 1)
|
|
240
238
|
} else {
|
|
241
239
|
queuedAudioTracks.append(item)
|
|
@@ -74,11 +74,11 @@ final class RmxAudioPlayer: NSObject {
|
|
|
74
74
|
|
|
75
75
|
let startPaused = options["startPaused"] != nil ? (options["startPaused"] as? Bool) ?? false : true
|
|
76
76
|
|
|
77
|
-
if
|
|
77
|
+
if playFromPosition > 0.0 {
|
|
78
|
+
seekToPosition = playFromPosition
|
|
79
|
+
}
|
|
80
|
+
else if retainPosition {
|
|
78
81
|
seekToPosition = getTrackCurrentTime(nil)
|
|
79
|
-
if playFromPosition > 0.0 {
|
|
80
|
-
seekToPosition = playFromPosition
|
|
81
|
-
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
let result = findTrack(byId: playFromId)
|
|
@@ -149,8 +149,10 @@ final class RmxAudioPlayer: NSObject {
|
|
|
149
149
|
guard (0..<avQueuePlayer.queuedAudioTracks.count).contains(index) else {
|
|
150
150
|
throw "Provided index is out of bounds"
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
avQueuePlayer.
|
|
152
|
+
|
|
153
|
+
if avQueuePlayer.currentIndex() != index {
|
|
154
|
+
avQueuePlayer.setCurrentIndex(index)
|
|
155
|
+
}
|
|
154
156
|
playCommand(false)
|
|
155
157
|
|
|
156
158
|
if positionTime != nil {
|
|
@@ -162,13 +164,15 @@ final class RmxAudioPlayer: NSObject {
|
|
|
162
164
|
guard !avQueuePlayer.queuedAudioTracks.isEmpty else {
|
|
163
165
|
throw "The playlist is empty!"
|
|
164
166
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
|
|
168
|
+
if avQueuePlayer.currentAudioTrack?.trackId != trackId {
|
|
169
|
+
let result = findTrack(byId: trackId)
|
|
170
|
+
let idx = result?["index"] as? Int ?? -1
|
|
171
|
+
guard idx >= 0 else {
|
|
172
|
+
throw "Track ID not found"
|
|
173
|
+
}
|
|
174
|
+
avQueuePlayer.setCurrentIndex(idx)
|
|
169
175
|
}
|
|
170
|
-
|
|
171
|
-
avQueuePlayer.setCurrentIndex(idx)
|
|
172
176
|
playCommand(false)
|
|
173
177
|
|
|
174
178
|
if positionTime != nil {
|
|
@@ -257,14 +261,13 @@ final class RmxAudioPlayer: NSObject {
|
|
|
257
261
|
if resetStreamOnPause,
|
|
258
262
|
let currentTrack = avQueuePlayer.currentAudioTrack,
|
|
259
263
|
currentTrack.isStream {
|
|
264
|
+
print( "music-stream-play")
|
|
260
265
|
avQueuePlayer.seek(to: .positiveInfinity, toleranceBefore: .zero, toleranceAfter: .zero)
|
|
261
266
|
currentTrack.seek(to: .positiveInfinity, toleranceBefore: .zero, toleranceAfter: .zero, completionHandler: nil)
|
|
262
267
|
}
|
|
263
268
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
print("\(action)")
|
|
267
|
-
}
|
|
269
|
+
print( "music-controls-play ")
|
|
270
|
+
|
|
268
271
|
avQueuePlayer.play()
|
|
269
272
|
}
|
|
270
273
|
|
|
@@ -529,11 +532,15 @@ final class RmxAudioPlayer: NSObject {
|
|
|
529
532
|
// only fire on real change!
|
|
530
533
|
let player = object as? AVBidirectionalQueuePlayer
|
|
531
534
|
let playerItem = player?.currentAudioTrack
|
|
532
|
-
|
|
535
|
+
if playerItem != nil {
|
|
536
|
+
guard self.lastTrackId != playerItem?.trackId else {
|
|
533
537
|
return // todo should call super instead or?
|
|
534
538
|
}
|
|
535
|
-
lastTrackId
|
|
539
|
+
print("observe change currentItem: lastTrackId \(self.lastTrackId) playerItem: \(playerItem?.trackId)")
|
|
540
|
+
self.lastTrackId = playerItem?.trackId
|
|
536
541
|
handleCurrentItemChanged(playerItem)
|
|
542
|
+
}
|
|
543
|
+
|
|
537
544
|
case "rate":
|
|
538
545
|
guard lastRate != change[.newKey] as? Float else {
|
|
539
546
|
return // todo should call super instead or?
|
|
@@ -594,7 +601,6 @@ final class RmxAudioPlayer: NSObject {
|
|
|
594
601
|
}
|
|
595
602
|
|
|
596
603
|
func updateNowPlayingTrackInfo(_ playerItem: AudioTrack?, updateTrackData: Bool) {
|
|
597
|
-
|
|
598
604
|
let currentItem = playerItem ?? avQueuePlayer.currentAudioTrack
|
|
599
605
|
let nowPlayingInfoCenter = MPNowPlayingInfoCenter.default()
|
|
600
606
|
if updatedNowPlayingInfo == nil {
|
|
@@ -638,7 +644,6 @@ final class RmxAudioPlayer: NSObject {
|
|
|
638
644
|
guard let coverUri = coverUriOrNil else {
|
|
639
645
|
return nil
|
|
640
646
|
}
|
|
641
|
-
|
|
642
647
|
var coverImage: UIImage? = nil
|
|
643
648
|
if coverUri.hasPrefix("http://") || coverUri.hasPrefix("https://") {
|
|
644
649
|
let coverImageUrl = URL(string: coverUri)!
|
|
@@ -754,9 +759,10 @@ final class RmxAudioPlayer: NSObject {
|
|
|
754
759
|
isWaitingToStartPlayback = false
|
|
755
760
|
var errorMsg = ""
|
|
756
761
|
if playerItem.error != nil {
|
|
762
|
+
print("\(playerItem.error)")
|
|
757
763
|
errorMsg = "Error playing audio track: \((playerItem.error as NSError?)?.localizedFailureReason ?? "")"
|
|
758
764
|
}
|
|
759
|
-
print("AVPlayerItemStatusFailed:
|
|
765
|
+
print("AVPlayerItemStatusFailed: \(errorMsg)")
|
|
760
766
|
let errorParam = createError(withCode: .rmxerr_DECODE, message: errorMsg)
|
|
761
767
|
onStatus(.rmxstatus_ERROR, trackId: playerItem.trackId, param: errorParam)
|
|
762
768
|
case .unknown:
|
|
@@ -989,9 +995,6 @@ final class RmxAudioPlayer: NSObject {
|
|
|
989
995
|
}
|
|
990
996
|
|
|
991
997
|
func removeTrackObservers(_ playerItem: AudioTrack?) {
|
|
992
|
-
playerItem?.removeObserver(self, forKeyPath: "status")
|
|
993
|
-
playerItem?.removeObserver(self, forKeyPath: "duration")
|
|
994
|
-
playerItem?.removeObserver(self, forKeyPath: "loadedTimeRanges")
|
|
995
998
|
NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: playerItem)
|
|
996
999
|
NotificationCenter.default.removeObserver(self, name: .AVPlayerItemPlaybackStalled, object: playerItem)
|
|
997
1000
|
|
|
@@ -1024,10 +1027,6 @@ final class RmxAudioPlayer: NSObject {
|
|
|
1024
1027
|
func observeLifeCycle() {
|
|
1025
1028
|
let listener = NotificationCenter.default
|
|
1026
1029
|
|
|
1027
|
-
// These aren't really needed. the AVQueuePlayer handles this for us.
|
|
1028
|
-
// [listener addObserver:self selector:@selector(handleEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
|
|
1029
|
-
// [listener addObserver:self selector:@selector(handleEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
|
|
1030
|
-
|
|
1031
1030
|
// We do need these.
|
|
1032
1031
|
listener.addObserver(self, selector: #selector(handleAudioSessionInterruption(_:)), name: AVAudioSession.interruptionNotification, object: AVAudioSession.sharedInstance())
|
|
1033
1032
|
|
|
@@ -1060,11 +1059,6 @@ final class RmxAudioPlayer: NSObject {
|
|
|
1060
1059
|
|
|
1061
1060
|
/// Cleanup
|
|
1062
1061
|
func deregisterMusicControlsEventListener() {
|
|
1063
|
-
// We don't use the remote control, and no need to remove observer on
|
|
1064
|
-
// NSNotificationCenter, that is done automatically
|
|
1065
|
-
// [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
|
|
1066
|
-
// [[NSNotificationCenter defaultCenter] removeObserver:self name:@"receivedEvent" object:nil];
|
|
1067
|
-
|
|
1068
1062
|
let commandCenter = MPRemoteCommandCenter.shared()
|
|
1069
1063
|
commandCenter.playCommand.removeTarget(self)
|
|
1070
1064
|
commandCenter.pauseCommand.removeTarget(self)
|
|
@@ -1079,7 +1073,6 @@ final class RmxAudioPlayer: NSObject {
|
|
|
1079
1073
|
|
|
1080
1074
|
func onReset() {
|
|
1081
1075
|
// Override to cancel any long-running requests when the WebView navigates or refreshes.
|
|
1082
|
-
//super.onReset()
|
|
1083
1076
|
releaseResources()
|
|
1084
1077
|
}
|
|
1085
1078
|
|
|
@@ -1087,9 +1080,6 @@ final class RmxAudioPlayer: NSObject {
|
|
|
1087
1080
|
if let playbackTimeObserver = playbackTimeObserver {
|
|
1088
1081
|
avQueuePlayer.removeTimeObserver(playbackTimeObserver)
|
|
1089
1082
|
}
|
|
1090
|
-
avQueuePlayer.removeObserver(self as NSObject, forKeyPath: "currentItem")
|
|
1091
|
-
avQueuePlayer.removeObserver(self as NSObject, forKeyPath: "rate")
|
|
1092
|
-
avQueuePlayer.removeObserver(self as NSObject, forKeyPath: "timeControlStatus")
|
|
1093
1083
|
deregisterMusicControlsEventListener()
|
|
1094
1084
|
|
|
1095
1085
|
removeAllTracks()
|
package/package.json
CHANGED
package/android/.gitignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/build
|
package/android/.npmignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/build
|