From 3b1eefaabbc8ba94699f8cf49783dc29482a6da0 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Mon, 27 Jun 2022 21:46:36 -0700 Subject: [PATCH] [Play Counts] Track play counts of correct track Track play counts for the correct track, even on short tracks. Also correctly track the play count of the last played item in the play queue which stops with bufferChain set to nil, so the previous iteration was not tracking it. Signed-off-by: Christopher Snowhill --- Audio/AudioPlayer.h | 2 ++ Audio/AudioPlayer.m | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Audio/AudioPlayer.h b/Audio/AudioPlayer.h index 6b32151e7..c7e40cbf7 100644 --- a/Audio/AudioPlayer.h +++ b/Audio/AudioPlayer.h @@ -39,6 +39,8 @@ using std::atomic_bool; id nextStreamUserInfo; NSDictionary *nextStreamRGInfo; + id previousUserInfo; // Track currently last heard track for play counts + id delegate; BOOL outputLaunched; diff --git a/Audio/AudioPlayer.m b/Audio/AudioPlayer.m index 7b57b346b..5bd379238 100644 --- a/Audio/AudioPlayer.m +++ b/Audio/AudioPlayer.m @@ -113,6 +113,7 @@ outputLaunched = NO; startedPaused = paused; initialBufferFilled = NO; + previousUserInfo = userInfo; [bufferChain launchThreads]; @@ -296,6 +297,8 @@ - (BOOL)endOfInputReached:(BufferChain *)sender // Sender is a BufferChain { + previousUserInfo = [sender userInfo]; + BufferChain *newChain = nil; if(atomic_load_explicit(&resettingNow, memory_order_relaxed)) @@ -424,9 +427,7 @@ } - (void)reportPlayCount { - if(bufferChain) { - [self reportPlayCountForTrack:[bufferChain userInfo]]; - } + [self reportPlayCountForTrack:previousUserInfo]; } - (BOOL)selectNextBuffer {