Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 006b94ea10 | |||
| abb0a29fb4 | |||
| ed3ba9698d | |||
| c25071d83a | |||
| 19db1fc74b |
@@ -115,10 +115,11 @@ class AudioDiskEngine: AudioEngine {
|
||||
}
|
||||
|
||||
let playing = playerNode.isPlaying
|
||||
let seekToNeedle = needle > Needle(duration) ? Needle(duration) : needle
|
||||
|
||||
self.needle = needle // to tick while paused
|
||||
self.needle = seekToNeedle // to tick while paused
|
||||
|
||||
seekFrame = AVAudioFramePosition(Float(needle) * audioSampleRate)
|
||||
seekFrame = AVAudioFramePosition(Float(seekToNeedle) * audioSampleRate)
|
||||
seekFrame = max(seekFrame, 0)
|
||||
seekFrame = min(seekFrame, audioLengthSamples)
|
||||
currentPosition = seekFrame
|
||||
|
||||
@@ -273,6 +273,15 @@ class AudioStreamEngine: AudioEngine {
|
||||
//MARK:- Overriden From Parent
|
||||
override func seek(toNeedle needle: Needle) {
|
||||
Log.info("didSeek to needle: \(needle)")
|
||||
|
||||
// if not playable (data not loaded etc), duration could be zero.
|
||||
guard isPlayable else {
|
||||
if predictedStreamDuration == 0 {
|
||||
seekNeedleCommandBeforeEngineWasReady = needle
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
guard needle < (ceil(predictedStreamDuration)) else {
|
||||
if !isPlayable {
|
||||
seekNeedleCommandBeforeEngineWasReady = needle
|
||||
|
||||
@@ -30,10 +30,12 @@ protocol AudioDataManagable {
|
||||
var numberOfActive: Int { get }
|
||||
|
||||
var allowCellular: Bool { get set }
|
||||
var downloadDirectory: FileManager.SearchPathDirectory { get }
|
||||
|
||||
func setHTTPHeaderFields(_ fields: [String: String]?)
|
||||
func setBackgroundCompletionHandler(_ completionHandler: @escaping () -> ())
|
||||
func setAllowCellularDownloadPreference(_ preference: Bool)
|
||||
func setDownloadDirectory(_ dir: FileManager.SearchPathDirectory)
|
||||
|
||||
func clear()
|
||||
|
||||
@@ -54,6 +56,7 @@ protocol AudioDataManagable {
|
||||
|
||||
class AudioDataManager: AudioDataManagable {
|
||||
var allowCellular: Bool = true
|
||||
var downloadDirectory: FileManager.SearchPathDirectory = .documentDirectory
|
||||
|
||||
static let shared: AudioDataManagable = AudioDataManager()
|
||||
|
||||
@@ -110,6 +113,10 @@ class AudioDataManager: AudioDataManagable {
|
||||
allowCellular = preference
|
||||
}
|
||||
|
||||
func setDownloadDirectory(_ dir: FileManager.SearchPathDirectory) {
|
||||
downloadDirectory = dir
|
||||
}
|
||||
|
||||
func attach(callback: @escaping (_ id: ID, _ progress: Double)->()) {
|
||||
globalDownloadProgressCallback = callback
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ struct FileStorage {
|
||||
// MARK:- Audio
|
||||
extension FileStorage {
|
||||
struct Audio {
|
||||
private static let directory: FileManager.SearchPathDirectory = .documentDirectory
|
||||
private static let directory: FileManager.SearchPathDirectory = AudioDataManager.shared.downloadDirectory
|
||||
private init() {}
|
||||
|
||||
static func isStored(_ id: ID) -> Bool {
|
||||
@@ -103,7 +103,7 @@ extension FileStorage {
|
||||
}
|
||||
|
||||
static func locate(_ id: ID) -> URL? {
|
||||
let folderUrls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
|
||||
let folderUrls = FileManager.default.urls(for: directory, in: .userDomainMask)
|
||||
guard folderUrls.count != 0 else { return nil }
|
||||
|
||||
if let urls = try? FileManager.default.contentsOfDirectory(at: folderUrls[0], includingPropertiesForKeys: nil) {
|
||||
|
||||
@@ -585,8 +585,7 @@ extension SAPlayer: SAPlayerDelegate {
|
||||
}
|
||||
|
||||
internal func seekEngine(toNeedle needle: Needle) {
|
||||
var seekToNeedle = needle < 0 ? 0 : needle
|
||||
seekToNeedle = needle > Needle(duration ?? 0) ? Needle(duration ?? 0) : needle
|
||||
let seekToNeedle = needle < 0 ? 0 : needle
|
||||
player?.seek(toNeedle: seekToNeedle)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,5 +109,14 @@ extension SAPlayer {
|
||||
AudioDataManager.shared.setAllowCellularDownloadPreference(allowUsingCellularData)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
EXPERIMENTAL!
|
||||
*/
|
||||
public static var downloadDirectory: FileManager.SearchPathDirectory = .documentDirectory {
|
||||
didSet {
|
||||
AudioDataManager.shared.setDownloadDirectory(downloadDirectory)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'SwiftAudioPlayer'
|
||||
s.version = '7.0.1'
|
||||
s.version = '7.1.0'
|
||||
s.summary = 'SwiftAudioPlayer is a Swift based audio player that can handle streaming from a remote location and audio manipulation.'
|
||||
|
||||
# This description is used to generate tags and improve search results.
|
||||
|
||||
Reference in New Issue
Block a user