I use AVQueuePlayer in my app and I need to have an array with my tracks with type [AVPlayerItem]. Array must creates every time when TableView loads. Also I have an array "content" with elements in current folder to create a table view cells. How can I add these elements to array "playerQueue"?
class TableViewController: UITableViewController {
var currentDirectory: String?
var content: [String] = []
var player: AVQueuePlayer!
var playerQueue: [AVPlayerItem] = []
override func viewDidLoad() {
super.viewDidLoad()
reloadData()
}
func reloadData(needsReload: Bool = true) {
if currentDirectory == nil {
currentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
}
do {
content = try FileManager.default.contentsOfDirectory(atPath: currentDirectory! )
} catch {
content = []
}
if needsReload {
tableView.reloadData()
}
}