Cache playback position on pause. Should fix #19.
This commit is contained in:
parent
9d0ee7f1b8
commit
55ab0ce71c
|
@ -261,12 +261,10 @@ class MainActivity : AppCompatActivity() {
|
||||||
now_playing_title.text = track.title
|
now_playing_title.text = track.title
|
||||||
now_playing_album.text = track.artist.name
|
now_playing_album.text = track.artist.name
|
||||||
now_playing_toggle.icon = getDrawable(R.drawable.pause)
|
now_playing_toggle.icon = getDrawable(R.drawable.pause)
|
||||||
now_playing_progress.progress = 0
|
|
||||||
|
|
||||||
now_playing_details_title.text = track.title
|
now_playing_details_title.text = track.title
|
||||||
now_playing_details_artist.text = track.artist.name
|
now_playing_details_artist.text = track.artist.name
|
||||||
now_playing_details_toggle.icon = getDrawable(R.drawable.pause)
|
now_playing_details_toggle.icon = getDrawable(R.drawable.pause)
|
||||||
now_playing_details_progress.progress = 0
|
|
||||||
|
|
||||||
Picasso.get()
|
Picasso.get()
|
||||||
.maybeLoad(maybeNormalizeUrl(track.album.cover.original))
|
.maybeLoad(maybeNormalizeUrl(track.album.cover.original))
|
||||||
|
|
|
@ -38,6 +38,8 @@ class SearchActivity : AppCompatActivity() {
|
||||||
|
|
||||||
search.setOnQueryTextListener(object : androidx.appcompat.widget.SearchView.OnQueryTextListener {
|
search.setOnQueryTextListener(object : androidx.appcompat.widget.SearchView.OnQueryTextListener {
|
||||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||||
|
search.clearFocus()
|
||||||
|
|
||||||
query?.let {
|
query?.let {
|
||||||
val query = URLEncoder.encode(it, "UTF-8")
|
val query = URLEncoder.encode(it, "UTF-8")
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,14 @@ class PlayerService : Service() {
|
||||||
|
|
||||||
if (queue.current > -1) {
|
if (queue.current > -1) {
|
||||||
player.prepare(queue.datasources, true, true)
|
player.prepare(queue.datasources, true, true)
|
||||||
player.seekTo(queue.current, 0)
|
|
||||||
|
Cache.get(this, "progress")?.let { progress ->
|
||||||
|
player.seekTo(queue.current, progress.readLine().toLong())
|
||||||
|
|
||||||
|
val (current, duration, percent) = progress(true)
|
||||||
|
|
||||||
|
ProgressBus.send(current, duration, percent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerReceiver(headphonesUnpluggedReceiver, IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY))
|
registerReceiver(headphonesUnpluggedReceiver, IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY))
|
||||||
|
@ -257,6 +264,16 @@ class PlayerService : Service() {
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private fun state(state: Boolean) {
|
private fun state(state: Boolean) {
|
||||||
|
if (!state) {
|
||||||
|
val (progress, _, _) = progress()
|
||||||
|
|
||||||
|
Cache.set(
|
||||||
|
this@PlayerService,
|
||||||
|
"progress",
|
||||||
|
progress.toString().toByteArray()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (state && player.playbackState == Player.STATE_IDLE) {
|
if (state && player.playbackState == Player.STATE_IDLE) {
|
||||||
player.prepare(queue.datasources)
|
player.prepare(queue.datasources)
|
||||||
}
|
}
|
||||||
|
@ -305,8 +322,8 @@ class PlayerService : Service() {
|
||||||
player.previous()
|
player.previous()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun progress(): Triple<Int, Int, Int> {
|
private fun progress(force: Boolean = false): Triple<Int, Int, Int> {
|
||||||
if (!player.playWhenReady) return progressCache
|
if (!player.playWhenReady && !force) return progressCache
|
||||||
|
|
||||||
return queue.current()?.bestUpload()?.let { upload ->
|
return queue.current()?.bestUpload()?.let { upload ->
|
||||||
val current = player.currentPosition
|
val current = player.currentPosition
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
android:layout_margin="8dp"
|
android:layout_margin="8dp"
|
||||||
android:alpha="0"
|
android:alpha="0"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:cardCornerRadius="8dp"
|
app:cardCornerRadius="3dp"
|
||||||
app:cardElevation="12dp"
|
app:cardElevation="12dp"
|
||||||
app:layout_dodgeInsetEdges="bottom"
|
app:layout_dodgeInsetEdges="bottom"
|
||||||
tools:alpha="1"
|
tools:alpha="1"
|
||||||
|
|
Loading…
Reference in New Issue