I'm improving the code I have for my project.
I stuck with the process of calling videos by subfolders because the code reads all the mp4 files, it finds.
Applying different codes that I have found on the internet, but I end up breaking all the code without success. I would appreciate help or advice in this regard.
Attached image that shows the location of folders with the different videos that I would like to separate my view basic and intermediate folder import UIKit import AVKit import AVFoundation
class BasicLevel: UIViewController, UITableViewDataSource, UITableViewDelegate, AVPlayerViewControllerDelegate{
var videoArray = [String]()
@IBOutlet weak var videoView: UIView!
@IBOutlet weak var videoTableView: UITableView!
var videoVC = AVPlayerViewController()
override func viewDidLoad() {
super.viewDidLoad()
videoTableView.delegate = self
videoTableView.dataSource = self
videoView.addSubview(videoVC.view)
videoVC.view.frame = videoView.frame
videoVC.showsPlaybackControls = false
let filemanager = FileManager.default
let path = Bundle.main.resourcePath!
let allItems = try? filemanager.contentsOfDirectory(atPath: path)
for singleItem in allItems! {
if singleItem.hasSuffix("mp4") {
videoArray.append(singleItem)
}
}
if videoArray.count > 0 {
playTopVideo(value: 0)
}
}
func playTopVideo(value: Int) {
let nameComponent = videoArray[value].components(separatedBy: ".")
let name = nameComponent[0]
let path = Bundle.main.path(forResource: name, ofType: "mp4")
let url = URL(fileURLWithPath: path!)
videoVC.player = AVPlayer(url: url)
videoVC.player?.play()
}
}