|
@@ -7,6 +7,7 @@ import android.support.v4.media.session.PlaybackStateCompat
|
7
|
7
|
import android.util.Log
|
8
|
8
|
import androidx.lifecycle.MutableLiveData
|
9
|
9
|
import fr.forum_thalie.tsumugi.*
|
|
10
|
+import fr.forum_thalie.tsumugi.planning.Planning
|
10
|
11
|
import org.json.JSONObject
|
11
|
12
|
import java.net.URL
|
12
|
13
|
import java.text.ParseException
|
|
@@ -58,9 +59,10 @@ class PlayerStore {
|
58
|
59
|
|
59
|
60
|
private fun getTimestamp(s: String) : Long
|
60
|
61
|
{
|
61
|
|
- val dateFormat = SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault())
|
|
62
|
+ val dateFormat = SimpleDateFormat("yyyy-MM-dd hh:mm:ss z", Locale.getDefault())
|
62
|
63
|
try {
|
63
|
|
- val t: Date? = dateFormat.parse(s)
|
|
64
|
+ val t: Date? = dateFormat.parse("$s ${Planning.instance.timeZone.id}")
|
|
65
|
+ Log.d(tag, "date: $s -> $t")
|
64
|
66
|
return t!!.time
|
65
|
67
|
} catch (e: ParseException) {
|
66
|
68
|
e.printStackTrace()
|
|
@@ -90,16 +92,17 @@ class PlayerStore {
|
90
|
92
|
|
91
|
93
|
currentSong.stopTime.value = ends
|
92
|
94
|
|
|
95
|
+ val apiTime = getTimestamp(res.getJSONObject("station").getString("schedulerTime"))
|
93
|
96
|
// I noticed that the server has a big (3 to 9 seconds !!) offset for current time.
|
94
|
97
|
// we can measure it when the player is playing, to compensate it and have our progress bar perfectly timed
|
95
|
98
|
// latencyCompensator is set to null when beginPlaying() (we can't measure it at the moment we start playing, since we're in the middle of a song),
|
96
|
99
|
// at this moment, we set it to 0. Then, next time the updateApi is called when we're playing, we measure the latency and we set out latencyComparator.
|
97
|
100
|
if(isCompensatingLatency)
|
98
|
101
|
{
|
99
|
|
- latencyCompensator = getTimestamp(res.getJSONObject("station").getString("schedulerTime")) - (currentSong.startTime.value ?: getTimestamp(res.getJSONObject("station").getString("schedulerTime")))
|
100
|
|
- //[REMOVE LOG CALLS]Log.d((tag, "latency compensator set to ${(latencyCompensator).toFloat()/1000} s")
|
|
102
|
+ latencyCompensator = apiTime - (currentSong.startTime.value!!)
|
|
103
|
+ //[REMOVE LOG CALLS]Log.d(tag, "latency compensator set to ${(latencyCompensator).toFloat() / 1000} s")
|
101
|
104
|
}
|
102
|
|
- currentTime.value = getTimestamp(res.getJSONObject("station").getString("schedulerTime")) - (latencyCompensator)
|
|
105
|
+ currentTime.value = apiTime - (latencyCompensator)
|
103
|
106
|
|
104
|
107
|
/*
|
105
|
108
|
val listeners = resMain.getInt("listeners")
|