diff --git a/AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift b/AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift index 6204639..059b122 100644 --- a/AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift +++ b/AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift @@ -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. @@ -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) } @@ -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 @@ -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 {