tried to tweaked queue to be resilient even for ultra short jingles

remotes/origin/devel
yattoz 2020-01-17 19:26:17 +01:00
parent 669e1cdc70
commit 8774558b51
2 changed files with 11 additions and 16 deletions

View File

@ -62,7 +62,7 @@ class PlayerStore {
val dateFormat = SimpleDateFormat("yyyy-MM-dd hh:mm:ss z", Locale.getDefault()) val dateFormat = SimpleDateFormat("yyyy-MM-dd hh:mm:ss z", Locale.getDefault())
try { try {
val t: Date? = dateFormat.parse("$s ${Planning.instance.timeZone.id}") val t: Date? = dateFormat.parse("$s ${Planning.instance.timeZone.id}")
Log.d(tag, "date: $s -> $t") //[REMOVE LOG CALLS]Log.d(tag, "date: $s -> $t")
return t!!.time return t!!.time
} catch (e: ParseException) { } catch (e: ParseException) {
e.printStackTrace() e.printStackTrace()
@ -166,17 +166,8 @@ class PlayerStore {
// ################################################## // ##################################################
fun updateQueue() { fun updateQueue() {
if (queue.isNotEmpty()) { //[REMOVE LOG CALLS]Log.d(tag, queue.toString())
queue.remove(queue.first())
//[REMOVE LOG CALLS]Log.d((tag, queue.toString())
fetchLastRequest() fetchLastRequest()
isQueueUpdated.value = true
} else if (isInitialized) {
fetchLastRequest()
} else {
//[REMOVE LOG CALLS]Log.d((tag, "queue is empty! fetching anyway !!")
fetchLastRequest()
}
} }
fun updateLp() { fun updateLp() {
@ -195,6 +186,7 @@ class PlayerStore {
private fun fetchLastRequest() private fun fetchLastRequest()
{ {
isQueueUpdated.value = false
val sleepScrape: (Any?) -> String = { val sleepScrape: (Any?) -> String = {
/* we can maximize our chances to retrieve the last queued song by specifically waiting for the number of seconds we measure between ICY metadata and API change. /* we can maximize our chances to retrieve the last queued song by specifically waiting for the number of seconds we measure between ICY metadata and API change.
we add 2 seconds just to get a higher probability that the API has correctly updated. (the latency compensator can have a jitter of 1 second usually) we add 2 seconds just to get a higher probability that the API has correctly updated. (the latency compensator can have a jitter of 1 second usually)
@ -228,18 +220,21 @@ class PlayerStore {
initApi() initApi()
} else } else
*/ */
if (resMain.has("next") /*&& queue.isNotEmpty()*/) { if (resMain.has("next")) {
val queueJSON = val queueJSON =
resMain.getJSONObject("next") resMain.getJSONObject("next")
val t = extractSong(queueJSON) val t = extractSong(queueJSON)
if (queue.isNotEmpty() && (t == queue.last() || t == currentSong)) if (queue.isNotEmpty() && (t == queue.last() || t == currentSong) && isQueueUpdated.value == false)
{ {
//[REMOVE LOG CALLS]Log.d((tag, playerStoreTag + "Song already in there: $t") //[REMOVE LOG CALLS]Log.d(tag, playerStoreTag + "Song already in there: $t\nQueue:$queue")
Async(sleepScrape, post) Async(sleepScrape, post)
} else { } else {
if (queue.isNotEmpty())
queue.remove(queue.first())
queue.add(queue.size, t) queue.add(queue.size, t)
//[REMOVE LOG CALLS]Log.d(tag, playerStoreTag + "added last queue song: $t") //[REMOVE LOG CALLS]Log.d(tag, playerStoreTag + "added last queue song: $t")
isQueueUpdated.value = true isQueueUpdated.value = true
return // FUUUCK IT WAS CALLING THE ASYNC ONE MORE TIME AFTERWARDS !?
} }
} }
} }

View File

@ -48,7 +48,7 @@ class Song(artistTitle: String = "", _id : Int = 0) {
override fun equals(other: Any?) : Boolean override fun equals(other: Any?) : Boolean
{ {
val song: Song = other as Song val song: Song = other as Song
return this.title.value == song.title.value && this.artist.value == song.artist.value return this.title.value === song.title.value && this.artist.value === song.artist.value
} }
fun copy(song: Song) { fun copy(song: Song) {