Skip to content

Commit

Permalink
Merge d3744f2 into deb7374
Browse files Browse the repository at this point in the history
  • Loading branch information
postlund committed Dec 23, 2019
2 parents deb7374 + d3744f2 commit b819925
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions pyatv/mrp/__init__.py
Expand Up @@ -226,14 +226,20 @@ def total_time(self):
@property
def position(self):
"""Position in the playing media (seconds)."""
# If we don't have reference time, we can't do anything
if not self._state.timestamp:
return None

elapsed_time = self._state.metadata_field('elapsedTime')
if elapsed_time:
now = datetime.datetime.now()
diff = (now - self._state.timestamp).total_seconds()
if self.device_state == const.DEVICE_STATE_PLAYING:
return int(elapsed_time + diff)
return int(elapsed_time)
return None
now = datetime.datetime.now()
diff = (now - self._state.timestamp).total_seconds()

# If elapsed time is available, we make the assumption that
# it is zero (playback started at reference time)
elapsed_time = elapsed_time or 0
if self.device_state == const.DEVICE_STATE_PLAYING:
return int(elapsed_time + diff)
return int(elapsed_time)

def _get_command_info(self, command):
for cmd in self._state.supported_commands:
Expand Down
2 changes: 1 addition & 1 deletion pyatv/mrp/player_state.py
Expand Up @@ -23,7 +23,7 @@ def __init__(self):
"""Initialize a new PlayerState instance."""
self.playback_state = None
self.supported_commands = []
self.timestamp = 0
self.timestamp = None
self.items = []
self.location = 0

Expand Down

0 comments on commit b819925

Please sign in to comment.