Browse Source

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

yattoz 5 years ago
parent
commit
8774558b51

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

62
         val dateFormat = SimpleDateFormat("yyyy-MM-dd hh:mm:ss z", Locale.getDefault())
62
         val dateFormat = SimpleDateFormat("yyyy-MM-dd hh:mm:ss z", Locale.getDefault())
63
         try {
63
         try {
64
             val t: Date? = dateFormat.parse("$s ${Planning.instance.timeZone.id}")
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
             return t!!.time
66
             return t!!.time
67
         } catch (e: ParseException) {
67
         } catch (e: ParseException) {
68
             e.printStackTrace()
68
             e.printStackTrace()
166
     // ##################################################
166
     // ##################################################
167
 
167
 
168
     fun updateQueue() {
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
     fun updateLp() {
173
     fun updateLp() {
195
 
186
 
196
     private fun fetchLastRequest()
187
     private fun fetchLastRequest()
197
     {
188
     {
189
+        isQueueUpdated.value = false
198
         val sleepScrape: (Any?) -> String = {
190
         val sleepScrape: (Any?) -> String = {
199
             /* 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.
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
              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)
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
                     initApi()
220
                     initApi()
229
                 } else
221
                 } else
230
                 */
222
                 */
231
-                if (resMain.has("next") /*&& queue.isNotEmpty()*/) {
223
+                if (resMain.has("next")) {
232
                     val queueJSON =
224
                     val queueJSON =
233
                         resMain.getJSONObject("next")
225
                         resMain.getJSONObject("next")
234
                     val t = extractSong(queueJSON)
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
                         Async(sleepScrape, post)
230
                         Async(sleepScrape, post)
239
                     } else {
231
                     } else {
232
+                        if (queue.isNotEmpty())
233
+                            queue.remove(queue.first())
240
                         queue.add(queue.size, t)
234
                         queue.add(queue.size, t)
241
                         //[REMOVE LOG CALLS]Log.d(tag, playerStoreTag +  "added last queue song: $t")
235
                         //[REMOVE LOG CALLS]Log.d(tag, playerStoreTag +  "added last queue song: $t")
242
                         isQueueUpdated.value = true
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
     override fun equals(other: Any?) : Boolean
48
     override fun equals(other: Any?) : Boolean
49
     {
49
     {
50
         val song: Song = other as Song
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
     fun copy(song: Song) {
54
     fun copy(song: Song) {