@roitium/expo-orpheus 0.4.0 → 0.4.2
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.
|
@@ -45,6 +45,7 @@ class ExpoOrpheusModule : Module() {
|
|
|
45
45
|
|
|
46
46
|
// 记录上一首歌曲的 ID,用于在切歌时发送给 JS
|
|
47
47
|
private var lastMediaId: String? = null
|
|
48
|
+
private var lastTrackFinishedAt: Long = 0
|
|
48
49
|
|
|
49
50
|
private val durationCache = mutableMapOf<String, Long>()
|
|
50
51
|
|
|
@@ -173,6 +174,7 @@ class ExpoOrpheusModule : Module() {
|
|
|
173
174
|
AsyncFunction("clear") {
|
|
174
175
|
checkController()
|
|
175
176
|
controller?.clearMediaItems()
|
|
177
|
+
durationCache.clear()
|
|
176
178
|
}.runOnQueue(Queues.MAIN)
|
|
177
179
|
|
|
178
180
|
AsyncFunction("skipTo") { index: Int ->
|
|
@@ -290,6 +292,7 @@ class ExpoOrpheusModule : Module() {
|
|
|
290
292
|
val player = controller ?: return@AsyncFunction
|
|
291
293
|
if (clearQueue == true) {
|
|
292
294
|
player.clearMediaItems()
|
|
295
|
+
durationCache.clear()
|
|
293
296
|
}
|
|
294
297
|
val initialSize = player.mediaItemCount
|
|
295
298
|
player.addMediaItems(mediaItems)
|
|
@@ -323,7 +326,7 @@ class ExpoOrpheusModule : Module() {
|
|
|
323
326
|
context,
|
|
324
327
|
OrpheusDownloadService::class.java,
|
|
325
328
|
downloadRequest,
|
|
326
|
-
|
|
329
|
+
true
|
|
327
330
|
)
|
|
328
331
|
}
|
|
329
332
|
|
|
@@ -337,7 +340,7 @@ class ExpoOrpheusModule : Module() {
|
|
|
337
340
|
context,
|
|
338
341
|
OrpheusDownloadService::class.java,
|
|
339
342
|
downloadRequest,
|
|
340
|
-
|
|
343
|
+
true
|
|
341
344
|
)
|
|
342
345
|
}
|
|
343
346
|
return@AsyncFunction
|
|
@@ -488,6 +491,10 @@ class ExpoOrpheusModule : Module() {
|
|
|
488
491
|
val mediaId = currentItem.mediaId
|
|
489
492
|
|
|
490
493
|
val duration = player.duration
|
|
494
|
+
Log.d(
|
|
495
|
+
"Orpheus",
|
|
496
|
+
"onTimelineChanged: reason: $reason mediaId: $mediaId duration: $duration"
|
|
497
|
+
)
|
|
491
498
|
|
|
492
499
|
if (duration != C.TIME_UNSET && duration > 0) {
|
|
493
500
|
durationCache[mediaId] = duration
|
|
@@ -499,12 +506,23 @@ class ExpoOrpheusModule : Module() {
|
|
|
499
506
|
newPosition: Player.PositionInfo,
|
|
500
507
|
reason: Int
|
|
501
508
|
) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
509
|
+
val isAutoTransition = reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION
|
|
510
|
+
val isIndexChanged = oldPosition.mediaItemIndex != newPosition.mediaItemIndex
|
|
511
|
+
val lastMediaItem = oldPosition.mediaItem ?: return
|
|
512
|
+
val currentTime = System.currentTimeMillis()
|
|
513
|
+
if ((currentTime - lastTrackFinishedAt) < 200) {
|
|
514
|
+
return
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
Log.d(
|
|
518
|
+
"Orpheus",
|
|
519
|
+
"onPositionDiscontinuity: isAutoTransition:$isAutoTransition isIndexChanged: $isIndexChanged durationCache:$durationCache"
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
if (isAutoTransition || isIndexChanged) {
|
|
505
523
|
|
|
506
|
-
|
|
507
|
-
|
|
524
|
+
val duration = durationCache[lastMediaItem.mediaId] ?: return
|
|
525
|
+
lastTrackFinishedAt = currentTime
|
|
508
526
|
|
|
509
527
|
sendEvent(
|
|
510
528
|
"onTrackFinished", mapOf(
|