+char *get_time_string(struct timeval *newest_stime)
+{
+ struct timeval diff, adj_stream_start, tmp;
+ int total = 0, use_server_time = 1,
+ length_seconds = stat_task->length_seconds;
+
+ if (!stat_task->playing) {
+ if (length_seconds)
+ return NULL;
+ return make_message("%s:\n", status_item_list[SI_PLAY_TIME]);
+ }
+ if (audiod_status == AUDIOD_OFF)
+ goto out;
+ if (stat_task->sa_time_diff_sign > 0)
+ tv_diff(&stat_task->server_stream_start, &stat_task->sa_time_diff,
+ &adj_stream_start);
+ else
+ tv_add(&stat_task->server_stream_start, &stat_task->sa_time_diff,
+ &adj_stream_start);
+ tmp = adj_stream_start;
+ if (newest_stime && audiod_status == AUDIOD_ON) {
+ tv_diff(newest_stime, &adj_stream_start, &diff);
+ if (tv2ms(&diff) < 5000) {
+ tmp = *newest_stime;
+ use_server_time = 0;
+ }
+ }
+ tv_diff(now, &tmp, &diff);
+ total = diff.tv_sec + stat_task->offset_seconds;
+ if (total > length_seconds)
+ total = length_seconds;
+ if (total < 0)
+ total = 0;
+out:
+ return make_message(
+ "%s: %s%d:%02d [%d:%02d] (%d%%/%d:%02d)\n",
+ status_item_list[SI_PLAY_TIME],
+ use_server_time? "~" : "",
+ total / 60,
+ total % 60,
+ (length_seconds - total) / 60,
+ (length_seconds - total) % 60,
+ length_seconds? (total * 100 + length_seconds / 2) /
+ length_seconds : 0,
+ length_seconds / 60,
+ length_seconds % 60
+ );
+}
+