Fix Playback
This commit is contained in:
parent
d77ce4e0cc
commit
558eaf833a
2 changed files with 10 additions and 13 deletions
|
@ -28,7 +28,6 @@ import code.name.monkey.retromusic.extensions.showToast
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.repository.SongRepository
|
import code.name.monkey.retromusic.repository.SongRepository
|
||||||
import code.name.monkey.retromusic.service.MusicService
|
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.getExternalStorageDirectory
|
||||||
import code.name.monkey.retromusic.util.logE
|
import code.name.monkey.retromusic.util.logE
|
||||||
import com.google.android.gms.cast.framework.CastSession
|
import com.google.android.gms.cast.framework.CastSession
|
||||||
|
@ -220,14 +219,9 @@ object MusicPlayerRemote : KoinComponent {
|
||||||
) && musicService != null
|
) && musicService != null
|
||||||
) {
|
) {
|
||||||
musicService?.openQueue(queue, startPosition, startPlaying)
|
musicService?.openQueue(queue, startPosition, startPlaying)
|
||||||
if (PreferenceUtil.isShuffleModeOn)
|
|
||||||
setShuffleMode(MusicService.SHUFFLE_MODE_NONE)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Async
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun openAndShuffleQueue(queue: List<Song>, startPlaying: Boolean) {
|
fun openAndShuffleQueue(queue: List<Song>, startPlaying: Boolean) {
|
||||||
var startPosition = 0
|
var startPosition = 0
|
||||||
|
@ -448,12 +442,14 @@ object MusicPlayerRemote : KoinComponent {
|
||||||
if (songs != null && songs.isNotEmpty()) {
|
if (songs != null && songs.isNotEmpty()) {
|
||||||
openQueue(songs, 0, true)
|
openQueue(songs, 0, true)
|
||||||
} else {
|
} else {
|
||||||
// TODO the file is not listed in the media store
|
try {
|
||||||
context.showToast(R.string.unplayable_file)
|
context.showToast(R.string.unplayable_file)
|
||||||
|
} catch (e: Exception) {
|
||||||
logE("The file is not listed in the media store")
|
logE("The file is not listed in the media store")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getSongIdFromMediaProvider(uri: Uri): String {
|
private fun getSongIdFromMediaProvider(uri: Uri): String {
|
||||||
return DocumentsContract.getDocumentId(uri).split(":".toRegex())
|
return DocumentsContract.getDocumentId(uri).split(":".toRegex())
|
||||||
|
|
|
@ -765,12 +765,12 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
fun openTrackAndPrepareNextAt(position: Int, completion: (success: Boolean) -> Unit) {
|
fun openTrackAndPrepareNextAt(position: Int, completion: (success: Boolean) -> Unit) {
|
||||||
this.position = position
|
this.position = position
|
||||||
openCurrent { success ->
|
openCurrent { success ->
|
||||||
|
completion(success)
|
||||||
|
notifyChange(META_CHANGED)
|
||||||
|
notHandledMetaChangedForCurrentTrack = false
|
||||||
if (success) {
|
if (success) {
|
||||||
prepareNextImpl()
|
prepareNextImpl()
|
||||||
}
|
}
|
||||||
notifyChange(META_CHANGED)
|
|
||||||
notHandledMetaChangedForCurrentTrack = false
|
|
||||||
completion(success)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -829,12 +829,14 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun prepareNextImpl() {
|
fun prepareNextImpl() {
|
||||||
|
val start = System.currentTimeMillis()
|
||||||
try {
|
try {
|
||||||
val nextPosition = getNextPosition(false)
|
val nextPosition = getNextPosition(false)
|
||||||
playbackManager.setNextDataSource(getSongAt(nextPosition).uri.toString())
|
playbackManager.setNextDataSource(getSongAt(nextPosition).uri.toString())
|
||||||
this.nextPosition = nextPosition
|
this.nextPosition = nextPosition
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
}
|
}
|
||||||
|
println("Time Prepare Next: ${System.currentTimeMillis() - start}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleFavorite() {
|
fun toggleFavorite() {
|
||||||
|
@ -957,7 +959,6 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
mediaSession?.setQueueTitle(getString(R.string.now_playing_queue))
|
mediaSession?.setQueueTitle(getString(R.string.now_playing_queue))
|
||||||
mediaSession?.setQueue(playingQueue.toMediaSessionQueue())
|
mediaSession?.setQueue(playingQueue.toMediaSessionQueue())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
queuesRestored = true
|
queuesRestored = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue