@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,447 @@
|
|
|
1
|
+
package org.dwbn.plugins.playlist
|
|
2
|
+
|
|
3
|
+
import android.os.Handler
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
import android.util.Log
|
|
6
|
+
import com.devbrackets.android.playlistcore.data.MediaProgress
|
|
7
|
+
import com.getcapacitor.*
|
|
8
|
+
import com.getcapacitor.annotation.CapacitorPlugin
|
|
9
|
+
import org.dwbn.plugins.playlist.data.AudioTrack
|
|
10
|
+
import org.json.JSONArray
|
|
11
|
+
import org.json.JSONObject
|
|
12
|
+
import java.util.*
|
|
13
|
+
|
|
14
|
+
@CapacitorPlugin(name = "Playlist")
|
|
15
|
+
public class PlaylistPlugin : Plugin(), OnStatusReportListener {
|
|
16
|
+
var TAG = "PlaylistPlugin"
|
|
17
|
+
private var statusCallback: OnStatusCallback? = null
|
|
18
|
+
private var audioPlayerImpl: RmxAudioPlayer? = null
|
|
19
|
+
private var resetStreamOnPause = true
|
|
20
|
+
|
|
21
|
+
override fun load() {
|
|
22
|
+
audioPlayerImpl = RmxAudioPlayer(this, (this.context.applicationContext as App))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@PluginMethod
|
|
26
|
+
fun initialize(call: PluginCall) {
|
|
27
|
+
Handler(Looper.getMainLooper()).post {
|
|
28
|
+
statusCallback = OnStatusCallback(this)
|
|
29
|
+
onStatus(RmxAudioStatusMessage.RMXSTATUS_REGISTER, "INIT", null)
|
|
30
|
+
Log.i(TAG, "Initialized...")
|
|
31
|
+
|
|
32
|
+
audioPlayerImpl!!.resume()
|
|
33
|
+
call.resolve()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
@PluginMethod
|
|
37
|
+
fun setOptions(call: PluginCall) {
|
|
38
|
+
Handler(Looper.getMainLooper()).post {
|
|
39
|
+
val options: JSObject = call.getObject("options") ?: JSObject()
|
|
40
|
+
// resetStreamOnPause is a top-level option; "options" is reserved for notification options.
|
|
41
|
+
resetStreamOnPause =
|
|
42
|
+
call.getBoolean("resetStreamOnPause", this.resetStreamOnPause) ?: this.resetStreamOnPause
|
|
43
|
+
Log.i("AudioPlayerOptions", options.toString())
|
|
44
|
+
audioPlayerImpl!!.resetStreamOnPause = resetStreamOnPause
|
|
45
|
+
audioPlayerImpl!!.setOptions(options)
|
|
46
|
+
call.resolve()
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@PluginMethod
|
|
51
|
+
fun release(call: PluginCall) {
|
|
52
|
+
Handler(Looper.getMainLooper()).post {
|
|
53
|
+
destroyResources()
|
|
54
|
+
call.resolve()
|
|
55
|
+
Log.i(TAG, "released")
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@PluginMethod
|
|
60
|
+
fun setLoop(call: PluginCall) {
|
|
61
|
+
Handler(Looper.getMainLooper()).post {
|
|
62
|
+
val loop: Boolean = call.getBoolean("loop", audioPlayerImpl!!.playlistManager.loop)!!
|
|
63
|
+
audioPlayerImpl!!.playlistManager.loop = loop
|
|
64
|
+
call.resolve()
|
|
65
|
+
Log.i(TAG, "setLoop: " + (if (loop) "TRUE" else "FALSE"))
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@PluginMethod
|
|
70
|
+
fun setPlaylistItems(call: PluginCall) {
|
|
71
|
+
val items: JSArray = call.getArray("items")
|
|
72
|
+
val optionsArgs: JSONObject = call.getObject("options")
|
|
73
|
+
val options = PlaylistItemOptions(optionsArgs)
|
|
74
|
+
Handler(Looper.getMainLooper()).post {
|
|
75
|
+
|
|
76
|
+
val trackItems: ArrayList<AudioTrack> = getTrackItems(items)
|
|
77
|
+
audioPlayerImpl!!.playlistManager.setAllItems(trackItems, options)
|
|
78
|
+
for (playerItem in trackItems) {
|
|
79
|
+
if (playerItem.trackId != null) {
|
|
80
|
+
onStatus(
|
|
81
|
+
RmxAudioStatusMessage.RMXSTATUS_ITEM_ADDED,
|
|
82
|
+
playerItem.trackId,
|
|
83
|
+
playerItem.toDict()
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
call.resolve()
|
|
89
|
+
}
|
|
90
|
+
Log.i(TAG, "setPlaylistItems: " + items.toString())
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@PluginMethod
|
|
94
|
+
fun addItem(call: PluginCall) {
|
|
95
|
+
Handler(Looper.getMainLooper()).post {
|
|
96
|
+
val item: JSONObject = call.getObject("item")
|
|
97
|
+
val playerItem: AudioTrack? = getTrackItem(item)
|
|
98
|
+
audioPlayerImpl!!.getPlaylistManager().addItem(playerItem)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
if (playerItem?.trackId != null) {
|
|
102
|
+
onStatus(
|
|
103
|
+
RmxAudioStatusMessage.RMXSTATUS_ITEM_ADDED,
|
|
104
|
+
playerItem.trackId,
|
|
105
|
+
playerItem.toDict()
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
call.resolve()
|
|
109
|
+
Log.i(TAG, "addItem")
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@PluginMethod
|
|
114
|
+
fun addAllItems(call: PluginCall) {
|
|
115
|
+
Handler(Looper.getMainLooper()).post {
|
|
116
|
+
val items: JSONArray = call.getArray("items")
|
|
117
|
+
val trackItems = getTrackItems(items)
|
|
118
|
+
audioPlayerImpl!!.playlistManager.addAllItems(trackItems)
|
|
119
|
+
|
|
120
|
+
for (playerItem in trackItems) {
|
|
121
|
+
if (playerItem.trackId != null) {
|
|
122
|
+
onStatus(
|
|
123
|
+
RmxAudioStatusMessage.RMXSTATUS_ITEM_ADDED,
|
|
124
|
+
playerItem.trackId,
|
|
125
|
+
playerItem.toDict()
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
call.resolve()
|
|
130
|
+
Log.i(TAG, "addAllItems")
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@PluginMethod
|
|
135
|
+
fun removeItem(call: PluginCall) {
|
|
136
|
+
Handler(Looper.getMainLooper()).post {
|
|
137
|
+
val trackIndex: Int = call.getInt("index", -1)!!
|
|
138
|
+
val trackId: String = call.getString("id", "")!!
|
|
139
|
+
Log.i(TAG, "removeItem trackIn")
|
|
140
|
+
val item = audioPlayerImpl!!.playlistManager.removeItem(trackIndex, trackId)
|
|
141
|
+
|
|
142
|
+
if (item != null) {
|
|
143
|
+
onStatus(RmxAudioStatusMessage.RMXSTATUS_ITEM_REMOVED, item.trackId, item.toDict())
|
|
144
|
+
call.resolve()
|
|
145
|
+
} else {
|
|
146
|
+
call.reject("Could not find item!")
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@PluginMethod
|
|
152
|
+
fun removeItems(call: PluginCall) {
|
|
153
|
+
Handler(Looper.getMainLooper()).post {
|
|
154
|
+
val items: JSONArray = call.getArray("items")
|
|
155
|
+
|
|
156
|
+
val removals = ArrayList<TrackRemovalItem>()
|
|
157
|
+
for (index in 0 until items.length()) {
|
|
158
|
+
val entry = items.optJSONObject(index) ?: continue
|
|
159
|
+
val trackIndex = entry.optInt("index", -1)
|
|
160
|
+
val trackId = entry.optString("id", "")
|
|
161
|
+
removals.add(TrackRemovalItem(trackIndex, trackId))
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
val removedTracks = audioPlayerImpl!!.playlistManager.removeAllItems(removals)
|
|
165
|
+
for (removedItem in removedTracks) {
|
|
166
|
+
onStatus(
|
|
167
|
+
RmxAudioStatusMessage.RMXSTATUS_ITEM_REMOVED,
|
|
168
|
+
removedItem.trackId,
|
|
169
|
+
removedItem.toDict()
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
val result = JSObject()
|
|
174
|
+
result.put("removed", removedTracks.size)
|
|
175
|
+
call.resolve(result)
|
|
176
|
+
|
|
177
|
+
Log.i(TAG, "removeItems")
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
@PluginMethod
|
|
182
|
+
fun clearAllItems(call: PluginCall) {
|
|
183
|
+
Handler(Looper.getMainLooper()).post {
|
|
184
|
+
audioPlayerImpl!!.playlistManager.clearItems()
|
|
185
|
+
|
|
186
|
+
onStatus(RmxAudioStatusMessage.RMXSTATUS_PLAYLIST_CLEARED, "INVALID", null)
|
|
187
|
+
call.resolve()
|
|
188
|
+
|
|
189
|
+
Log.i(TAG, "clearAllItems")
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@PluginMethod
|
|
194
|
+
fun getPlaylist(call: PluginCall) {
|
|
195
|
+
Handler(Looper.getMainLooper()).post {
|
|
196
|
+
val playlistManager = audioPlayerImpl!!.playlistManager
|
|
197
|
+
val audioTracks = playlistManager.getAllItems()
|
|
198
|
+
val itemsArray = JSONArray()
|
|
199
|
+
|
|
200
|
+
for (track in audioTracks) {
|
|
201
|
+
itemsArray.put(track.toDict())
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
val result = JSObject()
|
|
205
|
+
result.put("items", itemsArray)
|
|
206
|
+
call.resolve(result)
|
|
207
|
+
|
|
208
|
+
Log.i(TAG, "getPlaylist: ${audioTracks.size} items")
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
@PluginMethod
|
|
213
|
+
fun play(call: PluginCall) {
|
|
214
|
+
Handler(Looper.getMainLooper()).post {
|
|
215
|
+
if (audioPlayerImpl!!.playlistManager.playlistHandler != null) {
|
|
216
|
+
val isPlaying =
|
|
217
|
+
(audioPlayerImpl!!.playlistManager.playlistHandler?.currentMediaPlayer != null
|
|
218
|
+
&& audioPlayerImpl!!.playlistManager.playlistHandler?.currentMediaPlayer?.isPlaying!!)
|
|
219
|
+
// There's a bug in the threaded repeater that it stacks up the repeat calls instead of ignoring
|
|
220
|
+
// additional ones or starting a new one. E.g. every time this is called, you'd get a new repeat cycle,
|
|
221
|
+
// meaning you get N updates per second. Ew.
|
|
222
|
+
if (!isPlaying) {
|
|
223
|
+
audioPlayerImpl!!.clearTrackSelectionSuppression()
|
|
224
|
+
audioPlayerImpl!!.playlistManager.playlistHandler?.play()
|
|
225
|
+
//audioPlayerImpl.getPlaylistManager().playlistHandler.seek(position)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
call.resolve()
|
|
230
|
+
|
|
231
|
+
Log.i(TAG, "play")
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
@PluginMethod
|
|
236
|
+
fun playTrackByIndex(call: PluginCall) {
|
|
237
|
+
Handler(Looper.getMainLooper()).post {
|
|
238
|
+
val index: Int =
|
|
239
|
+
call.getInt("index", audioPlayerImpl!!.playlistManager.currentPosition)!!
|
|
240
|
+
val seekPosition = (call.getFloat("position", 0f)!! * 1000.0f).toLong()
|
|
241
|
+
|
|
242
|
+
audioPlayerImpl!!.playlistManager.currentPosition = index
|
|
243
|
+
audioPlayerImpl!!.clearTrackSelectionSuppression()
|
|
244
|
+
audioPlayerImpl!!.playlistManager.beginPlayback(seekPosition, false)
|
|
245
|
+
|
|
246
|
+
call.resolve()
|
|
247
|
+
|
|
248
|
+
Log.i(TAG, "playTrackByIndex")
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
@PluginMethod
|
|
253
|
+
fun playTrackById(call: PluginCall) {
|
|
254
|
+
Handler(Looper.getMainLooper()).post {
|
|
255
|
+
val id: String = call.getString("id")!!
|
|
256
|
+
if ("" != id) {
|
|
257
|
+
// alternatively we could search for the item and set the current index to that item.
|
|
258
|
+
val code = id.hashCode()
|
|
259
|
+
val seekPosition = (call.getFloat("position", 0f)!! * 1000.0f).toLong()
|
|
260
|
+
audioPlayerImpl!!.playlistManager.setCurrentItem(code.toLong())
|
|
261
|
+
audioPlayerImpl!!.clearTrackSelectionSuppression()
|
|
262
|
+
audioPlayerImpl!!.playlistManager.beginPlayback(seekPosition, false)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
call.resolve()
|
|
266
|
+
|
|
267
|
+
Log.i(TAG, "playTrackById")
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
@PluginMethod
|
|
272
|
+
fun selectTrackByIndex(call: PluginCall) {
|
|
273
|
+
Handler(Looper.getMainLooper()).post {
|
|
274
|
+
val index: Int =
|
|
275
|
+
call.getInt("index", audioPlayerImpl!!.playlistManager.currentPosition)!!
|
|
276
|
+
|
|
277
|
+
audioPlayerImpl!!.playlistManager.currentPosition = index
|
|
278
|
+
audioPlayerImpl!!.prepareForTrackSelection(audioPlayerImpl!!.playlistManager.currentItem?.trackId)
|
|
279
|
+
|
|
280
|
+
val seekPosition = (call.getFloat("position", 0f)!! * 1000.0f).toLong()
|
|
281
|
+
|
|
282
|
+
audioPlayerImpl!!.playlistManager.beginPlayback(seekPosition, true)
|
|
283
|
+
|
|
284
|
+
call.resolve()
|
|
285
|
+
|
|
286
|
+
Log.i(TAG, "selectTrackByIndex")
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
@PluginMethod
|
|
292
|
+
fun selectTrackById(call: PluginCall) {
|
|
293
|
+
Handler(Looper.getMainLooper()).post {
|
|
294
|
+
val id: String = call.getString("id")!!
|
|
295
|
+
if ("" != id) {
|
|
296
|
+
// alternatively we could search for the item and set the current index to that item.
|
|
297
|
+
val code = id.hashCode()
|
|
298
|
+
audioPlayerImpl!!.playlistManager.setCurrentItem(code.toLong())
|
|
299
|
+
audioPlayerImpl!!.prepareForTrackSelection(id)
|
|
300
|
+
|
|
301
|
+
val seekPosition = (call.getFloat("position", 0f)!! * 1000.0f).toLong()
|
|
302
|
+
|
|
303
|
+
audioPlayerImpl!!.playlistManager.beginPlayback(seekPosition, true)
|
|
304
|
+
}
|
|
305
|
+
call.resolve()
|
|
306
|
+
|
|
307
|
+
Log.i(TAG, "selectTrackById")
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@PluginMethod
|
|
312
|
+
fun pause(call: PluginCall) {
|
|
313
|
+
Handler(Looper.getMainLooper()).post {
|
|
314
|
+
audioPlayerImpl!!.clearTrackSelectionSuppression()
|
|
315
|
+
if (audioPlayerImpl!!.playlistManager.isPlaying) {
|
|
316
|
+
audioPlayerImpl!!.playlistManager.playlistHandler?.pause(false)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
call.resolve()
|
|
320
|
+
|
|
321
|
+
Log.i(TAG, "pause")
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
@PluginMethod
|
|
326
|
+
fun skipForward(call: PluginCall) {
|
|
327
|
+
Handler(Looper.getMainLooper()).post {
|
|
328
|
+
audioPlayerImpl!!.playlistManager.invokeNext()
|
|
329
|
+
|
|
330
|
+
call.resolve()
|
|
331
|
+
|
|
332
|
+
Log.i(TAG, "skipForward")
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
@PluginMethod
|
|
337
|
+
fun skipBack(call: PluginCall) {
|
|
338
|
+
Handler(Looper.getMainLooper()).post {
|
|
339
|
+
audioPlayerImpl!!.playlistManager.invokePrevious()
|
|
340
|
+
|
|
341
|
+
call.resolve()
|
|
342
|
+
|
|
343
|
+
Log.i(TAG, "skipBack")
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
@PluginMethod
|
|
348
|
+
fun seekTo(call: PluginCall) {
|
|
349
|
+
Handler(Looper.getMainLooper()).post {
|
|
350
|
+
var position: Long = 0
|
|
351
|
+
val progress: MediaProgress? = audioPlayerImpl!!.playlistManager.currentProgress
|
|
352
|
+
if (progress != null) {
|
|
353
|
+
position = progress.position
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
val seekPosition =
|
|
357
|
+
(call.getFloat("position", position / 1000.0f)!! * 1000.0f).toLong()
|
|
358
|
+
|
|
359
|
+
val isPlaying: Boolean? =
|
|
360
|
+
audioPlayerImpl!!.playlistManager.playlistHandler?.currentMediaPlayer?.isPlaying
|
|
361
|
+
audioPlayerImpl!!.playlistManager.playlistHandler?.seek(seekPosition)
|
|
362
|
+
if (isPlaying === null || !isPlaying) {
|
|
363
|
+
audioPlayerImpl!!.playlistManager.playlistHandler?.pause(false)
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
call.resolve()
|
|
367
|
+
|
|
368
|
+
Log.i(TAG, "seekTo")
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
@PluginMethod
|
|
373
|
+
fun setPlaybackRate(call: PluginCall) {
|
|
374
|
+
Handler(Looper.getMainLooper()).post {
|
|
375
|
+
val speed =
|
|
376
|
+
call.getFloat("rate", audioPlayerImpl!!.playlistManager.getPlaybackSpeed())!!
|
|
377
|
+
audioPlayerImpl!!.playlistManager.setPlaybackSpeed(speed)
|
|
378
|
+
|
|
379
|
+
call.resolve()
|
|
380
|
+
|
|
381
|
+
Log.i(TAG, "setPlaybackRate")
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
@PluginMethod
|
|
386
|
+
fun setPlaybackVolume(call: PluginCall) {
|
|
387
|
+
Handler(Looper.getMainLooper()).post {
|
|
388
|
+
val volume = call.getFloat("volume", 1.0f)!!
|
|
389
|
+
audioPlayerImpl!!.setVolume(volume)
|
|
390
|
+
|
|
391
|
+
call.resolve()
|
|
392
|
+
|
|
393
|
+
Log.i(TAG, "setPlaybackVolume: $volume")
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
override fun handleOnDestroy() {
|
|
398
|
+
Log.d(TAG, "Plugin destroy")
|
|
399
|
+
super.handleOnDestroy()
|
|
400
|
+
destroyResources()
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
override fun onError(errorCode: RmxAudioErrorType?, trackId: String?, message: String?) {
|
|
404
|
+
if (statusCallback == null) {
|
|
405
|
+
return
|
|
406
|
+
}
|
|
407
|
+
val errorObj = OnStatusCallback.createErrorWithCode(errorCode, message)
|
|
408
|
+
onStatus(RmxAudioStatusMessage.RMXSTATUS_ERROR, trackId, errorObj)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
override fun onStatus(what: RmxAudioStatusMessage, trackId: String?, param: JSONObject?) {
|
|
412
|
+
if (statusCallback == null) {
|
|
413
|
+
return
|
|
414
|
+
}
|
|
415
|
+
statusCallback!!.onStatus(what, trackId, param)
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
private fun destroyResources() {
|
|
419
|
+
statusCallback = null
|
|
420
|
+
audioPlayerImpl!!.playlistManager.clearItems()
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
private fun getTrackItem(item: JSONObject?): AudioTrack? {
|
|
424
|
+
if (item != null) {
|
|
425
|
+
val track = AudioTrack(item)
|
|
426
|
+
return if (track.trackId != null) {
|
|
427
|
+
track
|
|
428
|
+
} else null
|
|
429
|
+
}
|
|
430
|
+
return null
|
|
431
|
+
}
|
|
432
|
+
private fun getTrackItems(items: JSONArray?): ArrayList<AudioTrack> {
|
|
433
|
+
val trackItems = ArrayList<AudioTrack>()
|
|
434
|
+
if (items != null && items.length() > 0) {
|
|
435
|
+
for (index in 0 until items.length()) {
|
|
436
|
+
val obj = items.optJSONObject(index)
|
|
437
|
+
val track: AudioTrack = getTrackItem(obj) ?: continue
|
|
438
|
+
trackItems.add(track)
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return trackItems
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
fun emit(name: String, data: JSObject) {
|
|
445
|
+
this.notifyListeners(name, data, true)
|
|
446
|
+
}
|
|
447
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
package org.dwbn.plugins.playlist;
|
|
2
|
+
|
|
3
|
+
public enum RmxAudioErrorType {
|
|
4
|
+
RMXERR_NONE_ACTIVE(0),
|
|
5
|
+
RMXERR_ABORTED(1),
|
|
6
|
+
RMXERR_NETWORK(2),
|
|
7
|
+
RMXERR_DECODE(3),
|
|
8
|
+
RMXERR_NONE_SUPPORTED(4);
|
|
9
|
+
|
|
10
|
+
private final int id;
|
|
11
|
+
RmxAudioErrorType(int id) { this.id = id; }
|
|
12
|
+
public int getValue() { return id; }
|
|
13
|
+
};
|