Skip to content

Commit c640590

Browse files
committed
Save current track info on track change
1 parent 1391249 commit c640590

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

app/src/main/kotlin/com/simplemobiletools/musicplayer/interfaces/QueueItemsDao.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ interface QueueItemsDao {
2020
@Query("SELECT * FROM queue_items WHERE is_current = 1")
2121
fun getCurrent(): QueueItem?
2222

23+
@Query("UPDATE queue_items SET is_current = 1 WHERE track_id = :trackId")
24+
fun saveCurrentTrack(trackId: Long)
25+
2326
@Query("UPDATE queue_items SET is_current = 1, last_position = :lastPosition WHERE track_id = :trackId")
24-
fun saveCurrentTrack(trackId: Long, lastPosition: Int)
27+
fun saveCurrentTrackProgress(trackId: Long, lastPosition: Int)
2528

2629
@Query("UPDATE queue_items SET track_order = :order WHERE track_id = :trackId")
2730
fun setOrder(trackId: Long, order: Int)

app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,13 +1100,17 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
11001100
}
11011101

11021102
private fun saveTrackProgress() {
1103-
if (mCurrTrack != null && getPosition() != 0) {
1103+
if (mCurrTrack != null) {
11041104
ensureBackgroundThread {
11051105
val trackId = mCurrTrack?.mediaStoreId ?: return@ensureBackgroundThread
1106-
val position = getPosition() ?: return@ensureBackgroundThread
1106+
val position = getPosition()
11071107
queueDAO.apply {
11081108
resetCurrent()
1109-
saveCurrentTrack(trackId, position)
1109+
if (position == null || position == 0) {
1110+
saveCurrentTrack(trackId)
1111+
} else {
1112+
saveCurrentTrackProgress(trackId, position)
1113+
}
11101114
}
11111115
}
11121116
}

0 commit comments

Comments
 (0)