From feccaf0498edea458e3305b5f713561af0aed9a1 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 21 Jan 2013 14:03:49 +0200 Subject: [PATCH] player: Fix not returning current position properly Current position should be returned for Get/GetAll not last position notified otherwise clients that are started after playback are not able to synchronize its position properly as it does no know how for how long the playback has advanced. --- profiles/audio/player.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/profiles/audio/player.c b/profiles/audio/player.c index f8920c9b8..841a57702 100644 --- a/profiles/audio/player.c +++ b/profiles/audio/player.c @@ -111,12 +111,31 @@ static struct pending_req *pending_new(GDBusPendingPropertySet id, return p; } +static uint32_t media_player_get_position(struct media_player *mp) +{ + double timedelta; + uint32_t sec, msec; + + if (g_strcmp0(mp->status, "playing") != 0) + return mp->position; + + timedelta = g_timer_elapsed(mp->progress, NULL); + + sec = (uint32_t) timedelta; + msec = (uint32_t) ((timedelta - sec) * 1000); + + return mp->position + sec * 1000 + msec; +} + static gboolean get_position(const GDBusPropertyTable *property, DBusMessageIter *iter, void *data) { struct media_player *mp = data; + uint32_t position; + + position = media_player_get_position(mp); - dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &mp->position); + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &position); return TRUE; } @@ -464,22 +483,6 @@ struct media_player *media_player_controller_create(const char *path) return mp; } -static uint32_t media_player_get_position(struct media_player *mp) -{ - double timedelta; - uint32_t sec, msec; - - if (g_strcmp0(mp->status, "playing") != 0) - return mp->position; - - timedelta = g_timer_elapsed(mp->progress, NULL); - - sec = (uint32_t) timedelta; - msec = (uint32_t) ((timedelta - sec) * 1000); - - return mp->position + sec * 1000 + msec; -} - void media_player_set_position(struct media_player *mp, uint32_t position) { DBG("%u", position); -- 2.11.0