change song if the current one is deleted or removed from playlist

This commit is contained in:
tibbi 2017-04-07 22:12:09 +02:00
parent 802f283466
commit 2063ed206c
2 changed files with 11 additions and 2 deletions

View file

@ -21,6 +21,7 @@ import com.simplemobiletools.musicplayer.extensions.dbHelper
import com.simplemobiletools.musicplayer.extensions.sendIntent
import com.simplemobiletools.musicplayer.helpers.EDIT
import com.simplemobiletools.musicplayer.helpers.EDITED_SONG
import com.simplemobiletools.musicplayer.helpers.NEXT
import com.simplemobiletools.musicplayer.helpers.REFRESH_LIST
import com.simplemobiletools.musicplayer.models.Song
import com.simplemobiletools.musicplayer.services.MusicService
@ -154,6 +155,9 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList<Song>, val
files.add(File(song.path))
removeSongs.add(song)
notifyItemRemoved(it)
if (song == MusicService.mCurrSong) {
activity.sendIntent(NEXT)
}
}
songs.removeAll(removeSongs)
@ -175,6 +179,9 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList<Song>, val
paths.add(song.path)
removeSongs.add(song)
notifyItemRemoved(it)
if (song == MusicService.mCurrSong) {
activity.sendIntent(NEXT)
}
}
songs.removeAll(removeSongs)

View file

@ -376,7 +376,8 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
}
private fun restartSong() {
setSong(mPlayedSongIndexes!![mPlayedSongIndexes!!.size - 1], false)
if (mPlayedSongIndexes!!.isNotEmpty())
setSong(mPlayedSongIndexes!![mPlayedSongIndexes!!.size - 1], false)
}
private fun playSong(intent: Intent) {
@ -401,7 +402,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
}
}
mCurrSong = mSongs!![songIndex]
mCurrSong = mSongs!![Math.min(songIndex, mSongs!!.size - 1)]
try {
val trackUri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, mCurrSong!!.id)
@ -419,6 +420,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
}
private fun handleEmptyPlaylist() {
mPlayer!!.pause()
mCurrSong = null
mBus!!.post(Events.SongChanged(null))
songStateChanged(false)