@@ -9,15 +9,17 @@ std::unique_ptr<PlayerState> PlayerImpl::queryPlayerState(ColumnsQuery* activeIt
99{
1010 auto state = std::make_unique<PlayerState>();
1111
12+ // Read position before obtaining playlist lock
13+ PlaylistItemPtr activeItem (ddbApi->streamer_get_playing_track ());
14+ auto activeItemPos = activeItem ? ddbApi->streamer_get_playpos () : -1 .0f ;
15+
1216 PlaylistLockGuard lock (playlistMutex_);
1317
1418 playlists_.ensureInitialized ();
1519
16- PlaylistItemPtr activeItem (ddbApi->streamer_get_playing_track ());
17-
1820 state->playbackState = getPlaybackState (activeItem.get ());
1921 queryInfo (&state->info );
20- queryActiveItem (&state->activeItem , activeItem.get (), activeItemQuery);
22+ queryActiveItem (&state->activeItem , activeItem.get (), activeItemPos, activeItemQuery);
2123 queryVolume (&state->volume );
2224 queryOptions (state.get ());
2325 return state;
@@ -51,7 +53,8 @@ PlaybackState PlayerImpl::getPlaybackState(ddb_playItem_t* activeItem)
5153 }
5254}
5355
54- void PlayerImpl::queryActiveItem (ActiveItemInfo* info, ddb_playItem_t* activeItem, ColumnsQuery* query)
56+ void PlayerImpl::queryActiveItem (
57+ ActiveItemInfo* info, ddb_playItem_t* activeItem, float activeItemPos, ColumnsQuery* query)
5558{
5659 int playlistIndex = ddbApi->streamer_get_current_playlist ();
5760
@@ -64,13 +67,11 @@ void PlayerImpl::queryActiveItem(ActiveItemInfo* info, ddb_playItem_t* activeIte
6467 playlistId = playlists_.getId (playlist.get ());
6568
6669 int32_t itemIndex = -1 ;
67- double itemPosition = -1.0 ;
6870 double itemDuration = -1.0 ;
6971 std::vector<std::string> columns;
7072
7173 if (activeItem)
7274 {
73- itemPosition = ddbApi->streamer_get_playpos ();
7475 itemDuration = ddbApi->pl_get_item_duration (activeItem);
7576
7677 if (playlist)
@@ -87,7 +88,7 @@ void PlayerImpl::queryActiveItem(ActiveItemInfo* info, ddb_playItem_t* activeIte
8788 info->playlistId = std::move (playlistId);
8889 info->playlistIndex = playlistIndex;
8990 info->index = itemIndex;
90- info->position = itemPosition ;
91+ info->position = activeItemPos ;
9192 info->duration = itemDuration;
9293 info->columns = std::move (columns);
9394}
@@ -150,17 +151,18 @@ bool PlayerImpl::playNextBy(const std::string& expression, PlayerImpl::PlaylistI
150151 if (!format)
151152 throw InvalidRequestException (" invalid format expression: " + expression);
152153
154+ PlaylistItemPtr activeItem (ddbApi->streamer_get_playing_track ());
155+
156+ if (!activeItem)
157+ return false ;
158+
153159 PlaylistLockGuard lock (playlistMutex_);
154160
155161 int playlistIndex = ddbApi->streamer_get_current_playlist ();
156162 if (playlistIndex < 0 )
157163 return false ;
158164
159165 PlaylistPtr playlist (ddbApi->plt_get_for_idx (playlistIndex));
160- PlaylistItemPtr activeItem (ddbApi->streamer_get_playing_track ());
161-
162- if (!activeItem)
163- return false ;
164166
165167 ddb_tf_context_t context{};
166168 context._size = sizeof (context);
@@ -249,8 +251,6 @@ void PlayerImpl::setMuted(Switch value)
249251
250252void PlayerImpl::seekAbsolute (double offsetSeconds)
251253{
252- PlaylistLockGuard lock (playlistMutex_);
253-
254254 PlaylistItemPtr item (ddbApi->streamer_get_playing_track ());
255255 if (!item)
256256 return ;
@@ -260,8 +260,6 @@ void PlayerImpl::seekAbsolute(double offsetSeconds)
260260
261261void PlayerImpl::seekRelative (double offsetSeconds)
262262{
263- PlaylistLockGuard lock (playlistMutex_);
264-
265263 PlaylistItemPtr item (ddbApi->streamer_get_playing_track ());
266264 if (!item)
267265 return ;
0 commit comments