@mustafaj/capacitor-plugin-playlist 0.9.0
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/CapacitorPluginPlaylist.podspec +17 -0
- package/README.md +248 -0
- package/android/.project +34 -0
- package/android/build.gradle +69 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/android/gradle.properties +22 -0
- package/android/gradlew +251 -0
- package/android/gradlew.bat +94 -0
- package/android/proguard-rules.pro +21 -0
- package/android/settings.gradle +2 -0
- package/android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.java +26 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/App.kt +19 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/FakeR.kt +39 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/OnStatusCallback.kt +34 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/OnStatusReportListener.java +7 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/PlaylistItemOptions.java +52 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/PlaylistPlugin.kt +447 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/RmxAudioErrorType.java +13 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/RmxAudioPlayer.java +487 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/RmxAudioStatusMessage.java +35 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/RmxConstants.java +42 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/TrackRemovalItem.java +12 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/data/AudioTrack.kt +94 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/manager/MediaControlsListener.kt +13 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/manager/Options.kt +77 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/manager/PlaylistManager.kt +308 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/notification/PlaylistNotificationProvider.kt +26 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/playlist/AudioApi.kt +114 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/playlist/AudioPlaylistHandler.java +146 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/playlist/BaseMediaApi.kt +36 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/service/MediaImageProvider.kt +83 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/service/MediaService.kt +98 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/android/src/main/res/drawable/ic_closed_caption_white_24dp.xml +9 -0
- package/android/src/main/res/drawable/ic_demo_icon_adaptive.xml +15 -0
- package/android/src/main/res/drawable/ic_launcher_background.xml +48 -0
- package/android/src/main/res/drawable/ic_launcher_foreground.xml +22 -0
- package/android/src/main/res/drawable/ic_notification_icon.png +0 -0
- package/android/src/main/res/layout/bridge_layout_main.xml +15 -0
- package/android/src/main/res/values/colors.xml +3 -0
- package/android/src/main/res/values/strings.xml +3 -0
- package/android/src/main/res/values/styles.xml +3 -0
- package/android/src/test/java/com/getcapacitor/ExampleUnitTest.java +18 -0
- package/dist/docs.json +2071 -0
- package/dist/esm/Constants.d.ts +164 -0
- package/dist/esm/Constants.js +175 -0
- package/dist/esm/Constants.js.map +1 -0
- package/dist/esm/RmxAudioPlayer.d.ts +181 -0
- package/dist/esm/RmxAudioPlayer.js +344 -0
- package/dist/esm/RmxAudioPlayer.js.map +1 -0
- package/dist/esm/definitions.d.ts +78 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interfaces.d.ts +246 -0
- package/dist/esm/interfaces.js +2 -0
- package/dist/esm/interfaces.js.map +1 -0
- package/dist/esm/plugin.d.ts +3 -0
- package/dist/esm/plugin.js +13 -0
- package/dist/esm/plugin.js.map +1 -0
- package/dist/esm/utils.d.ts +15 -0
- package/dist/esm/utils.js +48 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/web.d.ts +54 -0
- package/dist/esm/web.js +409 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +993 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +996 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/AVBidirectionalQueuePlayer.swift +269 -0
- package/ios/Plugin/AudioTrack.swift +63 -0
- package/ios/Plugin/Constants.swift +39 -0
- package/ios/Plugin/DispatchQueue.swift +47 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Plugin.h +10 -0
- package/ios/Plugin/Plugin.m +30 -0
- package/ios/Plugin/Plugin.swift +208 -0
- package/ios/Plugin/RmxAudioPlayer.swift +1150 -0
- package/ios/Plugin.xcodeproj/project.pbxproj +574 -0
- package/ios/Plugin.xcworkspace/contents.xcworkspacedata +10 -0
- package/ios/Plugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/PluginTests/Info.plist +22 -0
- package/ios/PluginTests/PluginTests.swift +35 -0
- package/ios/Podfile +16 -0
- package/package.json +89 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <Capacitor/Capacitor.h>
|
|
3
|
+
|
|
4
|
+
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
+
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
+
CAP_PLUGIN(PlaylistPlugin, "Playlist",
|
|
7
|
+
CAP_PLUGIN_METHOD(setOptions, CAPPluginReturnPromise);
|
|
8
|
+
CAP_PLUGIN_METHOD(initialize, CAPPluginReturnPromise);
|
|
9
|
+
CAP_PLUGIN_METHOD(release, CAPPluginReturnPromise);
|
|
10
|
+
CAP_PLUGIN_METHOD(setPlaylistItems, CAPPluginReturnPromise);
|
|
11
|
+
CAP_PLUGIN_METHOD(addItem, CAPPluginReturnPromise);
|
|
12
|
+
CAP_PLUGIN_METHOD(addAllItems, CAPPluginReturnPromise);
|
|
13
|
+
CAP_PLUGIN_METHOD(removeItem, CAPPluginReturnPromise);
|
|
14
|
+
CAP_PLUGIN_METHOD(removeItems, CAPPluginReturnPromise);
|
|
15
|
+
CAP_PLUGIN_METHOD(clearAllItems, CAPPluginReturnPromise);
|
|
16
|
+
CAP_PLUGIN_METHOD(getPlaylist, CAPPluginReturnPromise);
|
|
17
|
+
CAP_PLUGIN_METHOD(play, CAPPluginReturnPromise);
|
|
18
|
+
CAP_PLUGIN_METHOD(pause, CAPPluginReturnPromise);
|
|
19
|
+
CAP_PLUGIN_METHOD(skipForward, CAPPluginReturnPromise);
|
|
20
|
+
CAP_PLUGIN_METHOD(skipBack, CAPPluginReturnPromise);
|
|
21
|
+
CAP_PLUGIN_METHOD(seekTo, CAPPluginReturnPromise);
|
|
22
|
+
CAP_PLUGIN_METHOD(playTrackByIndex, CAPPluginReturnPromise);
|
|
23
|
+
CAP_PLUGIN_METHOD(playTrackById, CAPPluginReturnPromise);
|
|
24
|
+
CAP_PLUGIN_METHOD(playTrackByIndex, CAPPluginReturnPromise);
|
|
25
|
+
CAP_PLUGIN_METHOD(selectTrackByIndex, CAPPluginReturnPromise);
|
|
26
|
+
CAP_PLUGIN_METHOD(selectTrackById, CAPPluginReturnPromise);
|
|
27
|
+
CAP_PLUGIN_METHOD(setPlaybackVolume, CAPPluginReturnPromise);
|
|
28
|
+
CAP_PLUGIN_METHOD(setLoop, CAPPluginReturnPromise);
|
|
29
|
+
CAP_PLUGIN_METHOD(setPlaybackRate, CAPPluginReturnPromise);
|
|
30
|
+
)
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
protocol StatusUpdater {
|
|
5
|
+
func onStatus(_ data: [String: Any])
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
9
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
10
|
+
*/
|
|
11
|
+
@objc(PlaylistPlugin)
|
|
12
|
+
public class PlaylistPlugin: CAPPlugin, StatusUpdater {
|
|
13
|
+
let audioPlayerImpl = RmxAudioPlayer()
|
|
14
|
+
|
|
15
|
+
// MARK: - Capacitor API
|
|
16
|
+
@objc func initialize(_ call: CAPPluginCall) {
|
|
17
|
+
// Ensure we don't drop the initial REGISTER status event.
|
|
18
|
+
audioPlayerImpl.statusUpdater = self
|
|
19
|
+
audioPlayerImpl.initialize()
|
|
20
|
+
call.resolve()
|
|
21
|
+
}
|
|
22
|
+
@objc func setOptions(_ call: CAPPluginCall) {
|
|
23
|
+
// setOptions is invoked with the full payload as the options object.
|
|
24
|
+
audioPlayerImpl.setOptions(call.options)
|
|
25
|
+
call.resolve()
|
|
26
|
+
}
|
|
27
|
+
@objc func release(_ call: CAPPluginCall) {
|
|
28
|
+
audioPlayerImpl.releaseResources()
|
|
29
|
+
call.resolve();
|
|
30
|
+
}
|
|
31
|
+
@objc func setPlaylistItems(_ call: CAPPluginCall) {
|
|
32
|
+
let items = call.getArray("items", [String:Any].self)!
|
|
33
|
+
let options = call.getObject("options")!
|
|
34
|
+
|
|
35
|
+
let tracks = createTracks(items)
|
|
36
|
+
audioPlayerImpl.setPlaylistItems(tracks, options: options)
|
|
37
|
+
|
|
38
|
+
call.resolve();
|
|
39
|
+
}
|
|
40
|
+
@objc func addItem(_ call: CAPPluginCall) {
|
|
41
|
+
let trackInfo = call.getObject("item")
|
|
42
|
+
|
|
43
|
+
let track = AudioTrack.initWithDictionary(trackInfo)
|
|
44
|
+
audioPlayerImpl.addItem(track!)
|
|
45
|
+
|
|
46
|
+
call.resolve();
|
|
47
|
+
}
|
|
48
|
+
@objc func addAllItems(_ call: CAPPluginCall) {
|
|
49
|
+
let items = call.getArray("items", [String:Any].self)!
|
|
50
|
+
|
|
51
|
+
let tracks = createTracks(items)
|
|
52
|
+
audioPlayerImpl.addAllItems(tracks)
|
|
53
|
+
call.resolve();
|
|
54
|
+
}
|
|
55
|
+
@objc func removeItem(_ call: CAPPluginCall) {
|
|
56
|
+
do {
|
|
57
|
+
// Prefer index if present.
|
|
58
|
+
if let index = call.getInt("index") {
|
|
59
|
+
try audioPlayerImpl.removeItem(index)
|
|
60
|
+
call.resolve()
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
if let id = call.getString("id") {
|
|
64
|
+
try audioPlayerImpl.removeItem(id)
|
|
65
|
+
call.resolve()
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
call.reject("Cannot remove: missing id or index")
|
|
69
|
+
} catch {
|
|
70
|
+
call.reject(String(describing: error))
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
@objc func removeItems(_ call: CAPPluginCall) {
|
|
74
|
+
guard let items = call.getArray("items") else {
|
|
75
|
+
call.reject("No Items")
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
let count = audioPlayerImpl.removeItems(items)
|
|
79
|
+
call.resolve([
|
|
80
|
+
"removed": count
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
@objc func clearAllItems(_ call: CAPPluginCall) {
|
|
84
|
+
audioPlayerImpl.clearAllItems()
|
|
85
|
+
call.resolve();
|
|
86
|
+
}
|
|
87
|
+
@objc func getPlaylist(_ call: CAPPluginCall) {
|
|
88
|
+
let tracks = audioPlayerImpl.avQueuePlayer.queuedAudioTracks
|
|
89
|
+
let items = tracks.map { $0.toDict() }
|
|
90
|
+
call.resolve(["items": items]);
|
|
91
|
+
}
|
|
92
|
+
@objc func play(_ call: CAPPluginCall) {
|
|
93
|
+
audioPlayerImpl.playCommand(false)
|
|
94
|
+
call.resolve();
|
|
95
|
+
}
|
|
96
|
+
@objc func pause(_ call: CAPPluginCall) {
|
|
97
|
+
audioPlayerImpl.pauseCommand(false)
|
|
98
|
+
call.resolve();
|
|
99
|
+
}
|
|
100
|
+
@objc func skipForward(_ call: CAPPluginCall) {
|
|
101
|
+
audioPlayerImpl.playNext(false)
|
|
102
|
+
call.resolve();
|
|
103
|
+
}
|
|
104
|
+
@objc func skipBack(_ call: CAPPluginCall) {
|
|
105
|
+
audioPlayerImpl.playPrevious(false)
|
|
106
|
+
call.resolve();
|
|
107
|
+
}
|
|
108
|
+
@objc func seekTo(_ call: CAPPluginCall) {
|
|
109
|
+
let to = call.getFloat("position", 0.0)
|
|
110
|
+
audioPlayerImpl.seek(to: to, isCommand: false)
|
|
111
|
+
call.resolve();
|
|
112
|
+
}
|
|
113
|
+
@objc func playTrackByIndex(_ call: CAPPluginCall) {
|
|
114
|
+
guard let index = call.getInt("index") else {
|
|
115
|
+
call.reject("Track index Invalid")
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
do {
|
|
120
|
+
try audioPlayerImpl.playTrack(index: index, positionTime: call.getFloat("position"))
|
|
121
|
+
call.resolve();
|
|
122
|
+
}
|
|
123
|
+
catch let message {
|
|
124
|
+
call.reject(message as! String)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
@objc func playTrackById(_ call: CAPPluginCall) {
|
|
128
|
+
guard let id = call.getString("id") else {
|
|
129
|
+
call.reject("Track Id Invalid")
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
do {
|
|
134
|
+
try audioPlayerImpl.playTrack(id, positionTime: call.getFloat("position"))
|
|
135
|
+
call.resolve();
|
|
136
|
+
}
|
|
137
|
+
catch let message {
|
|
138
|
+
call.reject(message as! String)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
@objc func selectTrackByIndex(_ call: CAPPluginCall) {
|
|
142
|
+
guard let index = call.getInt("index") else {
|
|
143
|
+
call.reject("Track index Invalid")
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
do {
|
|
148
|
+
try audioPlayerImpl.selectTrack(index: index)
|
|
149
|
+
call.resolve();
|
|
150
|
+
}
|
|
151
|
+
catch let message {
|
|
152
|
+
call.reject(message as! String)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
@objc func selectTrackById(_ call: CAPPluginCall) {
|
|
156
|
+
guard let id = call.getString("id") else {
|
|
157
|
+
call.reject("Track Id Invalid")
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
do {
|
|
162
|
+
try audioPlayerImpl.selectTrack(id: id)
|
|
163
|
+
call.resolve();
|
|
164
|
+
}
|
|
165
|
+
catch let message {
|
|
166
|
+
call.reject(message as! String)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
@objc func setPlaybackVolume(_ call: CAPPluginCall) {
|
|
170
|
+
let volume = call.getFloat("volume", 1)
|
|
171
|
+
audioPlayerImpl.setPlaybackVolume(volume)
|
|
172
|
+
call.resolve();
|
|
173
|
+
}
|
|
174
|
+
@objc func setLoop(_ call: CAPPluginCall) {
|
|
175
|
+
let loop = call.getBool("loop", true)
|
|
176
|
+
audioPlayerImpl.setLoopAll(loop)
|
|
177
|
+
call.resolve();
|
|
178
|
+
}
|
|
179
|
+
@objc func setPlaybackRate(_ call: CAPPluginCall) {
|
|
180
|
+
let rate = call.getFloat("rate", 1)
|
|
181
|
+
audioPlayerImpl.setPlaybackRate(rate)
|
|
182
|
+
call.resolve();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// MARK: - StatusUpdater delegate
|
|
186
|
+
// todo: calls to notifyListeners should be throttled
|
|
187
|
+
func onStatus(_ data: [String: Any]) {
|
|
188
|
+
notifyListeners("status", data: data)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// MARK: - Utility
|
|
192
|
+
func createTracks(_ items: [[String: Any]]?) -> [AudioTrack] {
|
|
193
|
+
if items == nil || items?.count == 0 {
|
|
194
|
+
return []
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
var newList: [AudioTrack] = []
|
|
198
|
+
for item in items ?? [] {
|
|
199
|
+
let track = AudioTrack.initWithDictionary(item)
|
|
200
|
+
if let track = track {
|
|
201
|
+
newList.append(track)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return newList;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
}
|