Reputation: 251
So far I’ve been working on a multiple audio playback project using AKPlayers
, triggered by AKSequencer
to obtain perfect sync, looping and advanced signal processing. It’s been going well, but now I need some insight before I jump into the next level.
I am trying to play the exact same function with remote mp3 files - streaming arrays of mp3 files from remote URL address. However, AKPlayer
so far doesn’t seem to support streaming functionality.
One possibility I found on this website, though, is Ryan Francesconi’s answer on the thread "How can I get AudioKit to stream an audio file from a remote URL?”. Here’s how he suggested:
guard let remote = URL(string: "https://www.sample-videos.com/audio/mp3/crowd-cheering.mp3"),
let data = NSData(contentsOf: remote) else {
AKLog("Remote failed to load.")
return
}
let cachedFile = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(remote.lastPathComponent)
try? data.write(to: cachedFile)
let player = AKPlayer(url: cachedFile)
So, before I start experimenting with this, could anybody (Mr. Francesconi, ideally) inform me how to implement this code on iOS? Would it be safe(in terms of seamless sync and looping) to develop with this cache-and-load idea for a multiple audio file playback project? Would be extremely helpful if I can learn more about this point. Much appreciated. <3
Upvotes: 2
Views: 773
Reputation: 6190
In terms of terminology this is not even a cache because cache is considered as temporary storage (and in case of iOS will be erased when the system thinks it's the best) while this approach actually saves data into the file system. In general I don't see that many risks with the idea of pre-downloading and then using downloaded files because you're working with filesystem and it's extremely fast.
The only thing I would really care for is for space being consumed by the downloaded files. You would probably need to clear your temporary files (if they're temporary) when app is inactive to avoid memory issues.
To better understand how and most importantly where your files will be stored please refer to Apple filesystem docs.
Upvotes: 2