简体   繁体   中英

How can i make an array of .mp4 or .mov files in Swift?

Ok So I'm trying to make an array of locally stored videos in Xcode. Can anyone help me out? I know how to program a tableView , I just need to use an array to pass that information (using the array of video files) to an AVPlayerKit Controller . in Swift.

So I had a similar issue before and what I ended up doing was creating a Model for my videos, which contained a property for storing the file data. This way I was able to make Sequence Types for my Model and use said sequence as a data source:

import Foundation

class MyVideo: Object{

var fileName: String?
var fileExtension: String?

func setVideoFileData(filePath: String){
    self.fileExtension = filePath.pathExtension
    self.fileName      = filePath.stringByDeletingPathExtension
}


}

And then in the my ViewController something like this:

var VideoCollection: Array<MyVideo>()

var newVideo = MyVideo()
newVideo.setVideoFileData("file.mp4")
VideoCollection.append(newVideo)

for video in VideoCollection{
    let videoURL: NSURL = NSBundle.mainBundle().URLForResource(video.fileName!, withExtension: video.fileExtension!)!
}

Of course you would first check those optionals fileName and fileExtension for nil instead of force unwrapping.

This would allow using your videos with Sequence Types.

This solution worked for what I needed, not sure it will be suited for what you need, but just an idea. Best of luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM