void SetNotificationPlaybackState(Notification.Builder builder) { var beginningOfTime = new DateTime (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); LogHelper.Debug (Tag, "updateNotificationPlaybackState. mPlaybackState=" + playbackState); if (playbackState == null || !started) { LogHelper.Debug (Tag, "updateNotificationPlaybackState. cancelling notification!"); service.StopForeground (true); return; } if (playbackState.State == PlaybackStateCode.Playing && playbackState.Position >= 0) { var timespan = ((long)(DateTime.UtcNow - beginningOfTime).TotalMilliseconds) - playbackState.Position; LogHelper.Debug (Tag, "updateNotificationPlaybackState. updating playback position to ", timespan / 1000, " seconds"); builder.SetWhen (timespan).SetShowWhen (true).SetUsesChronometer (true); } else { LogHelper.Debug (Tag, "updateNotificationPlaybackState. hiding playback position"); builder.SetWhen (0).SetShowWhen (false).SetUsesChronometer (false); } // Make sure that the notification can be dismissed by the user when we are not playing: builder.SetOngoing(playbackState.State == PlaybackStateCode.Playing); }