I’m working on a random audiofile playback project. I’m looking for a way to download random audio file from a remote server, but a playlist in advance for a seamless looping. I would like to get an idea about how to download a randomly selected file in advance during playback, instead of downloading it all at once.
When I was loading from a local device, it was easy: I created an array of AKPlayers
, each of them loaded with different audio files, and I triggered them through a random calling function (randomWithRepeats).
// Select random audiofile from 1-10, but repeat them 3-4 times.
let rand = RandomWithRepeats(range: 0...9, repeatRange: 3…4)
var players: [AKPlayer] = []
// This is triggered by AKSequencer's midi note
func playRandom() {
do {
let player = players1[rand.nextValue()]
player.play()
debugPrint("player1 \(player.audioFile!.fileName)")
}
}
But this time, it seems tricky because the file is placed on remote URL, google firebase.
So far I uploaded multiple audio files on firebase storage
, and created the exact same firebase database
in order to compare/update metadata. I was able to play audiofile randomly after I download the entire audio files. It was successful! But I am looking for a way to download only one or two files in advance because 1) it takes too much time to download everything in the first place, and 2) to save user’s data space.
Ideally, I am looking for a way to download files one by one, but randomly as AKPlayer will play the next. Just like playing Tetris, the user knows what blocks comes next but it is still random. (Perhaps related to some sort of playlist??) It will be much appreciated if I could get some advise here. <3