Revert "Revert "Expose the framesPlayed attribute so progress can be tracked …"

This reverts commit d3b563c7cd.
This commit is contained in:
Dimitris C.
2025-05-30 10:09:57 +03:00
committed by GitHub
parent d3b563c7cd
commit e7a6516e50
2 changed files with 15 additions and 0 deletions
@@ -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
@@ -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.