mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-18 11:44:44 +02:00
424 lines
15 KiB
Diff
424 lines
15 KiB
Diff
diff --git a/node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt b/node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt
|
|
index b2409a0..fb5d5a5 100644
|
|
--- a/node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt
|
|
+++ b/node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt
|
|
@@ -251,7 +251,7 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
}
|
|
|
|
@ReactMethod
|
|
- fun updateOptions(data: ReadableMap?, callback: Promise) = scope.launch {
|
|
+ fun updateOptions(data: ReadableMap?, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
val options = Arguments.toBundle(data)
|
|
@@ -262,9 +262,10 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun add(data: ReadableArray?, insertBeforeIndex: Int, callback: Promise) = scope.launch {
|
|
+ fun add(data: ReadableArray?, insertBeforeIndex: Int, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
try {
|
|
@@ -283,9 +284,10 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
rejectWithException(callback, exception)
|
|
}
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun load(data: ReadableMap?, callback: Promise) = scope.launch {
|
|
+ fun load(data: ReadableMap?, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
if (data == null) {
|
|
callback.resolve(null)
|
|
@@ -299,16 +301,18 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
callback.reject("invalid_track_object", "Track was not a dictionary type")
|
|
}
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun move(fromIndex: Int, toIndex: Int, callback: Promise) = scope.launch {
|
|
+ fun move(fromIndex: Int, toIndex: Int, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
musicService.move(fromIndex, toIndex)
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun remove(data: ReadableArray?, callback: Promise) = scope.launch {
|
|
+ fun remove(data: ReadableArray?, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
val inputIndexes = Arguments.toList(data)
|
|
if (inputIndexes != null) {
|
|
@@ -329,9 +333,10 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
}
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun updateMetadataForTrack(index: Int, map: ReadableMap?, callback: Promise) =
|
|
+ fun updateMetadataForTrack(index: Int, map: ReadableMap?, callback: Promise) {
|
|
scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
@@ -346,9 +351,10 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
callback.resolve(null)
|
|
}
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun updateNowPlayingMetadata(map: ReadableMap?, callback: Promise) = scope.launch {
|
|
+ fun updateNowPlayingMetadata(map: ReadableMap?, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
if (musicService.tracks.isEmpty())
|
|
@@ -362,9 +368,10 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun clearNowPlayingMetadata(callback: Promise) = scope.launch {
|
|
+ fun clearNowPlayingMetadata(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
if (musicService.tracks.isEmpty())
|
|
@@ -373,17 +380,19 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
musicService.clearNotificationMetadata()
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun removeUpcomingTracks(callback: Promise) = scope.launch {
|
|
+ fun removeUpcomingTracks(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.removeUpcomingTracks()
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun skip(index: Int, initialTime: Float, callback: Promise) = scope.launch {
|
|
+ fun skip(index: Int, initialTime: Float, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.skip(index)
|
|
@@ -394,9 +403,10 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun skipToNext(initialTime: Float, callback: Promise) = scope.launch {
|
|
+ fun skipToNext(initialTime: Float, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.skipToNext()
|
|
@@ -407,9 +417,10 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun skipToPrevious(initialTime: Float, callback: Promise) = scope.launch {
|
|
+ fun skipToPrevious(initialTime: Float, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.skipToPrevious()
|
|
@@ -420,9 +431,10 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun reset(callback: Promise) = scope.launch {
|
|
+ fun reset(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.stop()
|
|
@@ -431,135 +443,152 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun play(callback: Promise) = scope.launch {
|
|
+ fun play(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.play()
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun pause(callback: Promise) = scope.launch {
|
|
+ fun pause(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.pause()
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun stop(callback: Promise) = scope.launch {
|
|
+ fun stop(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.stop()
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun seekTo(seconds: Float, callback: Promise) = scope.launch {
|
|
+ fun seekTo(seconds: Float, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.seekTo(seconds)
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun seekBy(offset: Float, callback: Promise) = scope.launch {
|
|
+ fun seekBy(offset: Float, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.seekBy(offset)
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun retry(callback: Promise) = scope.launch {
|
|
+ fun retry(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.retry()
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun setVolume(volume: Float, callback: Promise) = scope.launch {
|
|
+ fun setVolume(volume: Float, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.setVolume(volume)
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getVolume(callback: Promise) = scope.launch {
|
|
+ fun getVolume(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
callback.resolve(musicService.getVolume())
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun setRate(rate: Float, callback: Promise) = scope.launch {
|
|
+ fun setRate(rate: Float, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.setRate(rate)
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getRate(callback: Promise) = scope.launch {
|
|
+ fun getRate(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
callback.resolve(musicService.getRate())
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun setRepeatMode(mode: Int, callback: Promise) = scope.launch {
|
|
+ fun setRepeatMode(mode: Int, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.setRepeatMode(RepeatMode.fromOrdinal(mode))
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getRepeatMode(callback: Promise) = scope.launch {
|
|
+ fun getRepeatMode(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
callback.resolve(musicService.getRepeatMode().ordinal)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun setPlayWhenReady(playWhenReady: Boolean, callback: Promise) = scope.launch {
|
|
+ fun setPlayWhenReady(playWhenReady: Boolean, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
musicService.playWhenReady = playWhenReady
|
|
callback.resolve(null)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getPlayWhenReady(callback: Promise) = scope.launch {
|
|
+ fun getPlayWhenReady(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
callback.resolve(musicService.playWhenReady)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getTrack(index: Int, callback: Promise) = scope.launch {
|
|
+ fun getTrack(index: Int, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
if (index >= 0 && index < musicService.tracks.size) {
|
|
- callback.resolve(Arguments.fromBundle(musicService.tracks[index].originalItem))
|
|
+ callback.resolve(musicService.tracks[index].originalItem?.let { Arguments.fromBundle(it) })
|
|
} else {
|
|
callback.resolve(null)
|
|
}
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getQueue(callback: Promise) = scope.launch {
|
|
+ fun getQueue(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
callback.resolve(Arguments.fromList(musicService.tracks.map { it.originalItem }))
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun setQueue(data: ReadableArray?, callback: Promise) = scope.launch {
|
|
+ fun setQueue(data: ReadableArray?, callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
try {
|
|
@@ -570,49 +599,54 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
rejectWithException(callback, exception)
|
|
}
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getActiveTrackIndex(callback: Promise) = scope.launch {
|
|
+ fun getActiveTrackIndex(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
callback.resolve(
|
|
if (musicService.tracks.isEmpty()) null else musicService.getCurrentTrackIndex()
|
|
)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getActiveTrack(callback: Promise) = scope.launch {
|
|
+ fun getActiveTrack(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
callback.resolve(
|
|
if (musicService.tracks.isEmpty()) null
|
|
- else Arguments.fromBundle(
|
|
- musicService.tracks[musicService.getCurrentTrackIndex()].originalItem
|
|
- )
|
|
+ else musicService.tracks[musicService.getCurrentTrackIndex()].originalItem
|
|
+ ?.let { Arguments.fromBundle(it) }
|
|
)
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getDuration(callback: Promise) = scope.launch {
|
|
+ fun getDuration(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
callback.resolve(musicService.getDurationInSeconds())
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getBufferedPosition(callback: Promise) = scope.launch {
|
|
+ fun getBufferedPosition(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
callback.resolve(musicService.getBufferedPositionInSeconds())
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getPosition(callback: Promise) = scope.launch {
|
|
+ fun getPosition(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
|
|
callback.resolve(musicService.getPositionInSeconds())
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getProgress(callback: Promise) = scope.launch {
|
|
+ fun getProgress(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
var bundle = Bundle()
|
|
bundle.putDouble("duration", musicService.getDurationInSeconds());
|
|
@@ -620,10 +654,12 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
|
|
bundle.putDouble("buffered", musicService.getBufferedPositionInSeconds());
|
|
callback.resolve(Arguments.fromBundle(bundle))
|
|
}
|
|
+ }
|
|
|
|
@ReactMethod
|
|
- fun getPlaybackState(callback: Promise) = scope.launch {
|
|
+ fun getPlaybackState(callback: Promise) { scope.launch {
|
|
if (verifyServiceBoundOrReject(callback)) return@launch
|
|
callback.resolve(Arguments.fromBundle(musicService.getPlayerStateBundle(musicService.state)))
|
|
}
|
|
+ }
|
|
}
|
|
diff --git a/node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt b/node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt
|
|
index afa6b0f..c6f01d5 100644
|
|
--- a/node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt
|
|
+++ b/node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt
|
|
@@ -741,7 +741,7 @@ class MusicService : HeadlessJsTaskService() {
|
|
|
|
@MainThread
|
|
private fun emit(event: String, data: Bundle? = null) {
|
|
- reactNativeHost.reactInstanceManager.currentReactContext
|
|
+ (applicationContext as? com.facebook.react.ReactApplication)?.reactHost?.currentReactContext
|
|
?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
?.emit(event, data?.let { Arguments.fromBundle(it) })
|
|
}
|
|
@@ -751,7 +751,7 @@ class MusicService : HeadlessJsTaskService() {
|
|
val payload = Arguments.createArray()
|
|
data.forEach { payload.pushMap(Arguments.fromBundle(it)) }
|
|
|
|
- reactNativeHost.reactInstanceManager.currentReactContext
|
|
+ (applicationContext as? com.facebook.react.ReactApplication)?.reactHost?.currentReactContext
|
|
?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
?.emit(event, payload)
|
|
}
|