From e7a6516e50de287ad61529baadfbcd308eb3f4f5 Mon Sep 17 00:00:00 2001 From: "Dimitris C." Date: Fri, 30 May 2025 10:09:57 +0300 Subject: [PATCH] =?UTF-8?q?Revert=20"Revert=20"Expose=20the=20framesPlayed?= =?UTF-8?q?=20attribute=20so=20progress=20can=20be=20tracked=20=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d3b563c7cd561aee481425a563c7e6d374638315. --- AudioStreaming/Streaming/Audio Entry/AudioEntry.swift | 5 +++++ AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/AudioStreaming/Streaming/Audio Entry/AudioEntry.swift b/AudioStreaming/Streaming/Audio Entry/AudioEntry.swift index 7494784..539d848 100644 --- a/AudioStreaming/Streaming/Audio Entry/AudioEntry.swift +++ b/AudioStreaming/Streaming/Audio Entry/AudioEntry.swift @@ -37,6 +37,11 @@ class AudioEntry { return seekTime + (Double(framesState.played) / outputAudioFormat.sampleRate) } + var framesPlayed: Int { + lock.lock(); defer { lock.unlock() } + return framesState.played + } + var audioStreamFormat = AudioStreamBasicDescription() /// Hold the seek time, if a seek was requested diff --git a/AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift b/AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift index a892c35..be8a5f3 100644 --- a/AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift +++ b/AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift @@ -81,6 +81,16 @@ open class AudioPlayer { return entry.progress } + /// The number of audio frames that have been played + public var framesPlayed: Int { + guard playerContext.internalState != .pendingNext else { return 0 } + playerContext.entriesLock.lock() + let playingEntry = playerContext.audioPlayingEntry + playerContext.entriesLock.unlock() + guard let entry = playingEntry else { return 0 } + return entry.framesPlayed + } + public private(set) var customAttachedNodes = [AVAudioNode]() /// The current configuration of the player.