I try to convert the code which i use to fetch image asset to fetch mp3 file on cloudkit. However, i can't figure the data part. I'm using this library to play audio. It only has one class called "AudioPlayer" so if i want to play music on local folder, it is enough to declare it.
https://github.com/tbaranes/AudioPlayerSwift
func loadSong(completion:@escaping (_ song: AudioPlayer?) -> ()) {
// 1
DispatchQueue.global(qos: DispatchQoS.QoSClass.background).async {
var song: AudioPlayer!
defer {
completion(song)
}
// 2
guard let asset = self.record["Song_File"] as? CKAsset else {
return
}
let songData: AudioPlayer
do {
songData = try Data(contentsOf: asset.fileURL)
} catch {
return
}
song = AudioPlayer(contentsOf: <#T##URL#>)
}
}
Actually, i can't do clearly what i want. (I wanted to stream a song from CloudKit, this one downloads the ckasset). Below code gets the URL of CkAsset so that i can put it in AVPlayer and play it.