Skip to content

Commit 31368a5

Browse files
authored
Revert "Revert "Expose the framesPlayed attribute so progress can be tracked …" (#111)
This reverts commit d3b563c.
1 parent d3b563c commit 31368a5

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

AudioStreaming/Streaming/Audio Entry/AudioEntry.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class AudioEntry {
3737
return seekTime + (Double(framesState.played) / outputAudioFormat.sampleRate)
3838
}
3939

40+
var framesPlayed: Int {
41+
lock.lock(); defer { lock.unlock() }
42+
return framesState.played
43+
}
44+
4045
var audioStreamFormat = AudioStreamBasicDescription()
4146

4247
/// Hold the seek time, if a seek was requested

AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ open class AudioPlayer {
8181
return entry.progress
8282
}
8383

84+
/// The number of audio frames that have been played
85+
public var framesPlayed: Int {
86+
guard playerContext.internalState != .pendingNext else { return 0 }
87+
playerContext.entriesLock.lock()
88+
let playingEntry = playerContext.audioPlayingEntry
89+
playerContext.entriesLock.unlock()
90+
guard let entry = playingEntry else { return 0 }
91+
return entry.framesPlayed
92+
}
93+
8494
public private(set) var customAttachedNodes = [AVAudioNode]()
8595

8696
/// The current configuration of the player.

0 commit comments

Comments
 (0)