代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| import UIKit
import AVFoundation
import AssetsLibrary
class ViewController: UIViewController {
override func viewDidLoad() {
let path = NSBundle.mainBundle().pathForResource("test", ofType: "mov")
let fileURL = NSURL(fileURLWithPath: path!)
let avAsset = AVURLAsset(URL: fileURL, options: nil)
let generator = AVAssetImageGenerator(asset: avAsset)
generator.maximumSize = self.view.frame.size
let capturedImage : CGImageRef! = generator.copyCGImageAtTime(avAsset.duration, actualTime: nil, error: nil)
let imageView = UIImageView(frame: self.view.frame)
imageView.image = UIImage(CGImage: capturedImage)
println(avAsset.duration)
self.view.addSubview(imageView)
}
}
|