Fixed autoplay

Fixed uncaught exception
Fixed playlist loading from file
This commit is contained in:
Nite 2021-10-19 21:02:51 +02:00 committed by tzugen
parent 24092ce465
commit 2847a51674
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
9 changed files with 34 additions and 16 deletions

View File

@ -15,4 +15,4 @@ abstract class ArtistOrIndex(
open var albumCount: Long? = null,
@Ignore
open var closeness: Int = 0
) : GenericEntry(id)
) : GenericEntry()

View File

@ -2,9 +2,8 @@ package org.moire.ultrasonic.domain
import androidx.room.Ignore
open class GenericEntry(
@Ignore override val id: String
) : Identifiable {
abstract class GenericEntry : Identifiable {
abstract override val id: String
@Ignore
open val name: String? = null
override fun compareTo(other: Identifiable): Int {

View File

@ -69,7 +69,7 @@ class MusicDirectory {
var bookmarkPosition: Int = 0,
var userRating: Int? = null,
var averageRating: Float? = null
) : Serializable, GenericEntry(id) {
) : Serializable, GenericEntry() {
fun setDuration(duration: Long) {
this.duration = duration.toInt()
}

View File

@ -10,4 +10,4 @@ import androidx.room.PrimaryKey
data class MusicFolder(
@PrimaryKey override val id: String,
override val name: String
) : GenericEntry(id)
) : GenericEntry()

View File

@ -10,7 +10,7 @@ data class Playlist @JvmOverloads constructor(
val songCount: String = "",
val created: String = "",
val public: Boolean? = null
) : Serializable, GenericEntry(id) {
) : Serializable, GenericEntry() {
companion object {
private const val serialVersionUID = -4160515427075433798L
}

View File

@ -8,7 +8,7 @@ data class PodcastsChannel(
val url: String?,
val description: String?,
val status: String?
) : Serializable, GenericEntry(id) {
) : Serializable, GenericEntry() {
companion object {
private const val serialVersionUID = -4160515427075433798L
}

View File

@ -13,7 +13,7 @@ data class Share(
var expires: String? = null,
var visitCount: Long? = null,
private val entries: MutableList<Entry> = mutableListOf()
) : Serializable, GenericEntry(id) {
) : Serializable, GenericEntry() {
override val name: String?
get() {
if (url != null) {

View File

@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData
import java.util.ArrayList
import java.util.PriorityQueue
import java.util.concurrent.Executors
import java.util.concurrent.RejectedExecutionException
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit
import org.koin.core.component.KoinComponent
@ -91,10 +92,21 @@ class Downloader(
}
fun checkDownloads() {
if (executorService == null || executorService!!.isTerminated) {
if (
executorService == null ||
executorService!!.isTerminated ||
executorService!!.isShutdown
) {
start()
} else {
executorService?.execute(downloadChecker)
try {
executorService?.execute(downloadChecker)
} catch (exception: RejectedExecutionException) {
Timber.w(
exception,
"checkDownloads() can't run, maybe the Downloader is shutting down..."
)
}
}
}

View File

@ -15,7 +15,9 @@ import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Handler
import android.os.IBinder
import android.os.Looper
import android.support.v4.media.session.MediaSessionCompat
import android.view.KeyEvent
import androidx.core.app.NotificationCompat
@ -159,7 +161,10 @@ class MediaPlayerService : Service() {
}
fun notifyDownloaderStopped() {
stopIfIdle()
// TODO It would be nice to know if the service really can be stopped instead of just
// checking if it is idle once...
val handler = Handler(Looper.getMainLooper())
handler.postDelayed({ stopIfIdle() }, 1000)
}
@Synchronized
@ -740,14 +745,16 @@ class MediaPlayerService : Service() {
private const val NOTIFICATION_CHANNEL_NAME = "Ultrasonic background service"
private const val NOTIFICATION_ID = 3033
@Volatile
private var instance: MediaPlayerService? = null
private val instanceLock = Any()
@JvmStatic
fun getInstance(): MediaPlayerService? {
val context = UApp.applicationContext()
synchronized(instanceLock) {
for (i in 0..19) {
for (i in 0..19) {
if (instance != null) return instance
synchronized(instanceLock) {
if (instance != null) return instance
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(
@ -756,10 +763,10 @@ class MediaPlayerService : Service() {
} else {
context.startService(Intent(context, MediaPlayerService::class.java))
}
Util.sleepQuietly(50L)
}
return instance
Util.sleepQuietly(100L)
}
return instance
}
@JvmStatic