Browse Source

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

yattoz 4 years ago
parent
commit
8774558b51

+ 10 - 15
app/src/main/java/fr/forum_thalie/tsumugi/playerstore/PlayerStore.kt View File

@@ -62,7 +62,7 @@ class PlayerStore {
62 62
         val dateFormat = SimpleDateFormat("yyyy-MM-dd hh:mm:ss z", Locale.getDefault())
63 63
         try {
64 64
             val t: Date? = dateFormat.parse("$s ${Planning.instance.timeZone.id}")
65
-            Log.d(tag, "date: $s -> $t")
65
+            //[REMOVE LOG CALLS]Log.d(tag, "date: $s -> $t")
66 66
             return t!!.time
67 67
         } catch (e: ParseException) {
68 68
             e.printStackTrace()
@@ -166,17 +166,8 @@ class PlayerStore {
166 166
     // ##################################################
167 167
 
168 168
     fun updateQueue() {
169
-        if (queue.isNotEmpty()) {
170
-            queue.remove(queue.first())
171
-            //[REMOVE LOG CALLS]Log.d((tag, queue.toString())
172
-            fetchLastRequest()
173
-            isQueueUpdated.value = true
174
-        } else if (isInitialized) {
175
-            fetchLastRequest()
176
-        } else {
177
-            //[REMOVE LOG CALLS]Log.d((tag,  "queue is empty! fetching anyway !!")
178
-            fetchLastRequest()
179
-        }
169
+        //[REMOVE LOG CALLS]Log.d(tag, queue.toString())
170
+        fetchLastRequest()
180 171
     }
181 172
 
182 173
     fun updateLp() {
@@ -195,6 +186,7 @@ class PlayerStore {
195 186
 
196 187
     private fun fetchLastRequest()
197 188
     {
189
+        isQueueUpdated.value = false
198 190
         val sleepScrape: (Any?) -> String = {
199 191
             /* 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.
200 192
              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 {
228 220
                     initApi()
229 221
                 } else
230 222
                 */
231
-                if (resMain.has("next") /*&& queue.isNotEmpty()*/) {
223
+                if (resMain.has("next")) {
232 224
                     val queueJSON =
233 225
                         resMain.getJSONObject("next")
234 226
                     val t = extractSong(queueJSON)
235
-                    if (queue.isNotEmpty() && (t == queue.last() || t == currentSong))
227
+                    if (queue.isNotEmpty() && (t == queue.last() || t == currentSong) && isQueueUpdated.value == false)
236 228
                     {
237
-                        //[REMOVE LOG CALLS]Log.d((tag, playerStoreTag +  "Song already in there: $t")
229
+                        //[REMOVE LOG CALLS]Log.d(tag, playerStoreTag +  "Song already in there: $t\nQueue:$queue")
238 230
                         Async(sleepScrape, post)
239 231
                     } else {
232
+                        if (queue.isNotEmpty())
233
+                            queue.remove(queue.first())
240 234
                         queue.add(queue.size, t)
241 235
                         //[REMOVE LOG CALLS]Log.d(tag, playerStoreTag +  "added last queue song: $t")
242 236
                         isQueueUpdated.value = true
237
+                        return // FUUUCK IT WAS CALLING THE ASYNC ONE MORE TIME AFTERWARDS !?
243 238
                     }
244 239
                 }
245 240
             }

+ 1 - 1
app/src/main/java/fr/forum_thalie/tsumugi/playerstore/Song.kt View File

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