Fix Playback

This commit is contained in:
Prathamesh More 2022-05-26 19:45:31 +05:30
parent d77ce4e0cc
commit 558eaf833a
2 changed files with 10 additions and 13 deletions

View file

@ -28,7 +28,6 @@ import code.name.monkey.retromusic.extensions.showToast
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.repository.SongRepository
import code.name.monkey.retromusic.service.MusicService
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.getExternalStorageDirectory
import code.name.monkey.retromusic.util.logE
import com.google.android.gms.cast.framework.CastSession
@ -220,14 +219,9 @@ object MusicPlayerRemote : KoinComponent {
) && musicService != null
) {
musicService?.openQueue(queue, startPosition, startPlaying)
if (PreferenceUtil.isShuffleModeOn)
setShuffleMode(MusicService.SHUFFLE_MODE_NONE)
}
}
/**
* Async
*/
@JvmStatic
fun openAndShuffleQueue(queue: List<Song>, startPlaying: Boolean) {
var startPosition = 0
@ -448,9 +442,11 @@ object MusicPlayerRemote : KoinComponent {
if (songs != null && songs.isNotEmpty()) {
openQueue(songs, 0, true)
} else {
// TODO the file is not listed in the media store
context.showToast(R.string.unplayable_file)
logE("The file is not listed in the media store")
try {
context.showToast(R.string.unplayable_file)
} catch (e: Exception) {
logE("The file is not listed in the media store")
}
}
}
}

View file

@ -765,12 +765,12 @@ class MusicService : MediaBrowserServiceCompat(),
fun openTrackAndPrepareNextAt(position: Int, completion: (success: Boolean) -> Unit) {
this.position = position
openCurrent { success ->
completion(success)
notifyChange(META_CHANGED)
notHandledMetaChangedForCurrentTrack = false
if (success) {
prepareNextImpl()
}
notifyChange(META_CHANGED)
notHandledMetaChangedForCurrentTrack = false
completion(success)
}
}
@ -829,12 +829,14 @@ class MusicService : MediaBrowserServiceCompat(),
@Synchronized
fun prepareNextImpl() {
val start = System.currentTimeMillis()
try {
val nextPosition = getNextPosition(false)
playbackManager.setNextDataSource(getSongAt(nextPosition).uri.toString())
this.nextPosition = nextPosition
} catch (ignored: Exception) {
}
println("Time Prepare Next: ${System.currentTimeMillis() - start}")
}
fun toggleFavorite() {
@ -957,7 +959,6 @@ class MusicService : MediaBrowserServiceCompat(),
mediaSession?.setQueueTitle(getString(R.string.now_playing_queue))
mediaSession?.setQueue(playingQueue.toMediaSessionQueue())
}
}
queuesRestored = true
}