mirror of
https://github.com/apognu/otter
synced 2025-02-22 05:17:37 +01:00
Fixed an issue where the main playback UI would freeze when skipping an erroring track (in airplane mode, for example).
This commit is contained in:
parent
1b98850a9c
commit
18e981fba5
@ -97,12 +97,12 @@ play {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
|
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
|
||||||
|
|
||||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61")
|
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.71")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.6")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.6")
|
||||||
|
|
||||||
implementation("androidx.appcompat:appcompat:1.1.0")
|
implementation("androidx.appcompat:appcompat:1.1.0")
|
||||||
implementation("androidx.core:core-ktx:1.4.0-alpha01")
|
implementation("androidx.core:core-ktx:1.5.0-alpha01")
|
||||||
implementation("androidx.coordinatorlayout:coordinatorlayout:1.1.0")
|
implementation("androidx.coordinatorlayout:coordinatorlayout:1.1.0")
|
||||||
implementation("androidx.preference:preference:1.1.1")
|
implementation("androidx.preference:preference:1.1.1")
|
||||||
implementation("androidx.recyclerview:recyclerview:1.1.0")
|
implementation("androidx.recyclerview:recyclerview:1.1.0")
|
||||||
|
@ -72,11 +72,19 @@ class MainActivity : AppCompatActivity() {
|
|||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
.replace(R.id.container, BrowseFragment())
|
.replace(R.id.container, BrowseFragment())
|
||||||
.commit()
|
.commit()
|
||||||
|
|
||||||
|
if (bus == null) {
|
||||||
|
watchEventBus()
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandBus.send(Command.RefreshService)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
|
CommandBus.send(Command.RefreshService)
|
||||||
|
|
||||||
startService(Intent(this, PlayerService::class.java))
|
startService(Intent(this, PlayerService::class.java))
|
||||||
DownloadService.start(this, PinService::class.java)
|
DownloadService.start(this, PinService::class.java)
|
||||||
|
|
||||||
@ -115,12 +123,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
landscape_queue?.let {
|
landscape_queue?.let {
|
||||||
supportFragmentManager.beginTransaction().replace(R.id.landscape_queue, LandscapeQueueFragment()).commit()
|
supportFragmentManager.beginTransaction().replace(R.id.landscape_queue, LandscapeQueueFragment()).commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bus == null) {
|
|
||||||
watchEventBus()
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandBus.send(Command.RefreshService)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
@ -489,12 +491,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private fun incrementListenCount(track: Track?) {
|
private fun incrementListenCount(track: Track?) {
|
||||||
track?.let {
|
track?.let {
|
||||||
GlobalScope.launch(IO) {
|
GlobalScope.launch(IO) {
|
||||||
Fuel
|
try {
|
||||||
.post(mustNormalizeUrl("/api/v1/history/listenings/"))
|
Fuel
|
||||||
.authorize()
|
.post(mustNormalizeUrl("/api/v1/history/listenings/"))
|
||||||
.header("Content-Type", "application/json")
|
.authorize()
|
||||||
.body(Gson().toJson(mapOf("track" to track.id)))
|
.header("Content-Type", "application/json")
|
||||||
.awaitStringResponse()
|
.body(Gson().toJson(mapOf("track" to track.id)))
|
||||||
|
.awaitStringResponse()
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ class PlayerService : Service() {
|
|||||||
EventBus.send(Event.QueueChanged)
|
EventBus.send(Event.QueueChanged)
|
||||||
|
|
||||||
if (queue.metadata.isNotEmpty()) {
|
if (queue.metadata.isNotEmpty()) {
|
||||||
EventBus.send(Event.RefreshTrack(queue.current(), player.playWhenReady))
|
EventBus.send(Event.RefreshTrack(queue.current()))
|
||||||
EventBus.send(Event.StateChanged(player.playWhenReady))
|
EventBus.send(Event.StateChanged(player.playWhenReady))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,12 +148,7 @@ class PlayerService : Service() {
|
|||||||
|
|
||||||
state(true)
|
state(true)
|
||||||
|
|
||||||
EventBus.send(
|
EventBus.send(Event.RefreshTrack(queue.current()))
|
||||||
Event.RefreshTrack(
|
|
||||||
queue.current(),
|
|
||||||
true
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is Command.AddToQueue -> queue.append(message.tracks)
|
is Command.AddToQueue -> queue.append(message.tracks)
|
||||||
@ -167,7 +162,7 @@ class PlayerService : Service() {
|
|||||||
|
|
||||||
state(true)
|
state(true)
|
||||||
|
|
||||||
EventBus.send(Event.RefreshTrack(queue.current(), true))
|
EventBus.send(Event.RefreshTrack(queue.current()))
|
||||||
}
|
}
|
||||||
|
|
||||||
is Command.ToggleState -> toggle()
|
is Command.ToggleState -> toggle()
|
||||||
@ -351,7 +346,6 @@ class PlayerService : Service() {
|
|||||||
when (playbackState) {
|
when (playbackState) {
|
||||||
Player.STATE_READY -> mediaControlsManager.updateNotification(queue.current(), true)
|
Player.STATE_READY -> mediaControlsManager.updateNotification(queue.current(), true)
|
||||||
Player.STATE_BUFFERING -> EventBus.send(Event.Buffering(true))
|
Player.STATE_BUFFERING -> EventBus.send(Event.Buffering(true))
|
||||||
Player.STATE_IDLE -> state(false)
|
|
||||||
Player.STATE_ENDED -> EventBus.send(Event.PlaybackStopped)
|
Player.STATE_ENDED -> EventBus.send(Event.PlaybackStopped)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,7 +353,6 @@ class PlayerService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
false -> {
|
false -> {
|
||||||
EventBus.send(Event.StateChanged(false))
|
|
||||||
EventBus.send(Event.Buffering(false))
|
EventBus.send(Event.Buffering(false))
|
||||||
|
|
||||||
if (playbackState == Player.STATE_READY) {
|
if (playbackState == Player.STATE_READY) {
|
||||||
@ -387,7 +380,7 @@ class PlayerService : Service() {
|
|||||||
|
|
||||||
Cache.set(this@PlayerService, "current", queue.current.toString().toByteArray())
|
Cache.set(this@PlayerService, "current", queue.current.toString().toByteArray())
|
||||||
|
|
||||||
EventBus.send(Event.RefreshTrack(queue.current(), true))
|
EventBus.send(Event.RefreshTrack(queue.current()))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPositionDiscontinuity(reason: Int) {
|
override fun onPositionDiscontinuity(reason: Int) {
|
||||||
@ -401,10 +394,12 @@ class PlayerService : Service() {
|
|||||||
override fun onPlayerError(error: ExoPlaybackException) {
|
override fun onPlayerError(error: ExoPlaybackException) {
|
||||||
EventBus.send(Event.PlaybackError(getString(R.string.error_playback)))
|
EventBus.send(Event.PlaybackError(getString(R.string.error_playback)))
|
||||||
|
|
||||||
queue.current()?.let {
|
queue.current++
|
||||||
queue.remove(it)
|
player.prepare(queue.datasources, true, true)
|
||||||
player.prepare(queue.datasources)
|
player.seekTo(queue.current, 0)
|
||||||
}
|
player.playWhenReady = true
|
||||||
|
|
||||||
|
EventBus.send(Event.RefreshTrack(queue.current()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package com.github.apognu.otter.utils
|
|||||||
import com.github.apognu.otter.Otter
|
import com.github.apognu.otter.Otter
|
||||||
import com.google.android.exoplayer2.offline.Download
|
import com.google.android.exoplayer2.offline.Download
|
||||||
import com.google.android.exoplayer2.offline.DownloadCursor
|
import com.google.android.exoplayer2.offline.DownloadCursor
|
||||||
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.Dispatchers.Main
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
@ -43,7 +44,7 @@ sealed class Event {
|
|||||||
class Buffering(val value: Boolean) : Event()
|
class Buffering(val value: Boolean) : Event()
|
||||||
class TrackPlayed(val track: Track?, val play: Boolean) : Event()
|
class TrackPlayed(val track: Track?, val play: Boolean) : Event()
|
||||||
class TrackFinished(val track: Track?) : Event()
|
class TrackFinished(val track: Track?) : Event()
|
||||||
class RefreshTrack(val track: Track?, val play: Boolean) : Event()
|
class RefreshTrack(val track: Track?) : Event()
|
||||||
class StateChanged(val playing: Boolean) : Event()
|
class StateChanged(val playing: Boolean) : Event()
|
||||||
object QueueChanged : Event()
|
object QueueChanged : Event()
|
||||||
object RadioStarted : Event()
|
object RadioStarted : Event()
|
||||||
@ -67,8 +68,8 @@ sealed class Response {
|
|||||||
|
|
||||||
object EventBus {
|
object EventBus {
|
||||||
fun send(event: Event) {
|
fun send(event: Event) {
|
||||||
GlobalScope.launch {
|
GlobalScope.launch(IO) {
|
||||||
Otter.get().eventBus.send(event)
|
Otter.get().eventBus.offer(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user