Skip to content

Commit 9ebd1f3

Browse files
committed
修复开启淡入淡出后切歌没有声音的问题
1 parent 5bb4484 commit 9ebd1f3

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

app/src/main/java/remix/myplayer/service/MusicService.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -791,19 +791,15 @@ class MusicService : BaseService(),
791791
*/
792792
private fun skipToNext() {
793793
playback.skipToNext()
794-
if (!playback.isPlaying) {
795-
playback.start()
796-
}
794+
start(true)
797795
}
798796

799797
/**
800798
* 播放上一首
801799
*/
802800
private fun skipToPrevious() {
803801
playback.skipToPrevious()
804-
if (!playback.isPlaying) {
805-
playback.start()
806-
}
802+
start(true)
807803
}
808804

809805
/**
@@ -904,9 +900,7 @@ class MusicService : BaseService(),
904900
}
905901

906902
playback.skipTo(position)
907-
if (!playback.isPlaying) {
908-
playback.start()
909-
}
903+
start(true)
910904
}
911905

912906
override fun onMediaStoreChanged() {

app/src/main/java/remix/myplayer/service/VolumeController.kt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package remix.myplayer.service
22

33
import android.animation.Animator
4+
import android.animation.AnimatorListenerAdapter
45
import android.animation.ValueAnimator
56
import android.os.Handler
67
import android.os.Looper
@@ -58,14 +59,22 @@ class VolumeController(private val service: MusicService) {
5859
service.playback.setVolume(volume)
5960
lastVolume = volume
6061
}
61-
if (onEnd != null) {
62-
addListener(object : Animator.AnimatorListener {
63-
override fun onAnimationStart(animation: Animator) = Unit
64-
override fun onAnimationEnd(animation: Animator) = onEnd()
65-
override fun onAnimationCancel(animation: Animator) = Unit
66-
override fun onAnimationRepeat(animation: Animator) = Unit
67-
})
68-
}
62+
addListener(object : AnimatorListenerAdapter() {
63+
private var canceled = false
64+
65+
override fun onAnimationCancel(animation: Animator) {
66+
canceled = true
67+
}
68+
69+
override fun onAnimationEnd(animation: Animator) {
70+
if (animator === animation) {
71+
animator = null
72+
}
73+
if (!canceled) {
74+
onEnd?.invoke()
75+
}
76+
}
77+
})
6978
}
7079
animator?.start()
7180
}
@@ -80,4 +89,4 @@ class VolumeController(private val service: MusicService) {
8089

8190
private const val DURATION_IN_MS = 400L
8291
}
83-
}
92+
}

0 commit comments

Comments
 (0)