Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ open class AudioPlayer {
return entry.framesPlayed
}

public var upcomingItems: [AudioEntryId] {
serializationQueue.sync {
return entriesQueue.items(type: .upcoming).map { $0.id }
}
}

public private(set) var customAttachedNodes = [AVAudioNode]()

/// The current configuration of the player.
Expand Down Expand Up @@ -287,7 +293,7 @@ open class AudioPlayer {
/// - parameter source: A `CoreAudioStreamSource` that will providing streaming data
/// - parameter entryId: A `String` that provides a unique id for this item
/// - parameter format: An `AVAudioFormat` the format of this audio source
public func queue(source: CoreAudioStreamSource, entryId: String, format: AVAudioFormat) {
public func queue(source: CoreAudioStreamSource, entryId: String, format: AVAudioFormat, after afterUrl: URL? = nil) {
let audioEntry = AudioEntry(source: source, entryId: AudioEntryId(id: entryId), outputAudioFormat: format)
queue(audioEntry: audioEntry)
}
Expand All @@ -314,7 +320,7 @@ open class AudioPlayer {
/// - parameter headers: A `Dictionary` specifying any additional headers to be pass to the network request.
public func queue(url: URL, headers: [String: String], after afterUrl: URL? = nil) {
let audioEntry = entryProvider.provideAudioEntry(url: url, headers: headers)
queue(audioEntry: audioEntry, after: afterUrl)
queue(audioEntry: audioEntry, after: afterUrl?.absoluteString)
}

/// Queues the specified URLs
Expand All @@ -335,11 +341,11 @@ open class AudioPlayer {
}
}

private func queue(audioEntry: AudioEntry, after afterUrl: URL? = nil) {
private func queue(audioEntry: AudioEntry, after afterId: String? = nil) {
serializationQueue.sync {
audioEntry.delegate = self
if let afterUrl = afterUrl {
if let afterUrlEntry = entriesQueue.items(type: .upcoming).first(where: { $0.id.id == afterUrl.absoluteString }) {
if let afterId {
if let afterUrlEntry = entriesQueue.items(type: .upcoming).first(where: { $0.id.id == afterId }) {
entriesQueue.insert(item: audioEntry, type: .upcoming, after: afterUrlEntry)
}
} else {
Expand Down
Loading