Prevent issue on queue item deletion. Should close #48.

This commit is contained in:
Antoine POPINEAU 2020-06-20 16:32:14 +02:00
parent e539cc26dd
commit 66c7915307
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
3 changed files with 16 additions and 3 deletions

View File

@ -45,7 +45,6 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.random.Random
class MainActivity : AppCompatActivity() {
enum class ResultCode(val code: Int) {

View File

@ -253,8 +253,6 @@ class PlayerService : Service() {
state(false)
player.release()
Otter.get().exoCache.release()
stopForeground(true)
stopSelf()

View File

@ -127,8 +127,24 @@ class QueueManager(val context: Context) {
fun remove(track: Track) {
metadata.indexOf(track).let {
if (it < 0) {
return
}
datasources.removeMediaSource(it)
metadata.removeAt(it)
if (it == current) {
CommandBus.send(Command.NextTrack)
}
if (it < current) {
current--
}
}
if (metadata.isEmpty()) {
current = -1
}
persist()