@@ -533,6 +533,7 @@ class WukongService : Service() {
533
533
534
534
Protocol .PRELOAD -> {
535
535
val song = protocol.song!!
536
+ Log .i(TAG , " debounce preload: ${song.songKey} ${song.title} " )
536
537
debounce.run {
537
538
try {
538
539
// Preload artwork image.
@@ -572,16 +573,19 @@ class WukongService : Service() {
572
573
573
574
currentPlayUserId = protocol.user
574
575
currentPlayUser = User .getUserFromList(userList, currentPlayUserId) ? : currentPlayUser
575
-
576
576
downvoted = protocol.downvote ? : false
577
- val oldStartTime = songStartTime
578
- songStartTime = currentTimeMillis() - ((if (protocol.elapsed!! <= 10 ) 0 .toFloat() else protocol.elapsed) * 1000 ).toLong()
579
577
578
+ Log .i(TAG , " Play: ${song.songKey} ${song.title} by user ${currentPlayUser?.userName} " )
579
+
580
+ val oldStartTime = songStartTime
581
+ songStartTime = currentTimeMillis() - (protocol.elapsed * 1000 ).toLong()
580
582
// Reduce noise or glitch.
581
583
if (currentSong?.songKey == song.songKey && Math .abs(songStartTime - oldStartTime) < 5000 ) {
582
584
Log .i(TAG , " server may send exactly the same song ${song.songKey} , skipping" )
583
585
return
584
586
}
587
+ // Play from the beginning if elapsed time is too short.
588
+ songStartTime = currentTimeMillis() - ((if (protocol.elapsed <= 10 ) 0 .toFloat() else protocol.elapsed) * 1000 ).toLong()
585
589
586
590
mediaPlayer.reset()
587
591
currentSong = song
@@ -639,7 +643,7 @@ class WukongService : Service() {
639
643
640
644
Protocol .NOTIFICATION -> {
641
645
handler.post {
642
- Toast .makeText(applicationContext, " Wukong: " + protocol.notification?.message, Toast .LENGTH_SHORT ).show()
646
+ Toast .makeText(applicationContext, " Wukong: " + protocol.notification?.message, Toast .LENGTH_LONG ).show()
643
647
}
644
648
}
645
649
}
0 commit comments