【发布时间】:2015-04-16 17:02:29
【问题描述】:
我正在尝试在通用 UIView 容器中显示使用 UIImagePickerController 捕获的电影,但它无法正常工作。容器视图可见,但容器视图中不显示视频。
我已将代码放入 didFinishPickingMediaWithInfo,这就是我目前所拥有的。捕获工作正常,我得到了一个有效的电影 url,但我不确定我是否可以/应该将 moviePlayer.view 作为子视图添加到容器中,以及它的大小是否正确。我希望scalingMode = .AspectFill 能解决这个问题。
@IBOutlet weak var videoContainer: UIView!
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
dismissViewControllerAnimated(true, completion: nil)
if let movieUrl = info[UIImagePickerControllerMediaURL] as? NSURL {
println("Movie url found: \(movieUrl)")
let moviePlayer = MPMoviePlayerController(contentURL: movieUrl)
moviePlayer.controlStyle = MPMovieControlStyle.None
moviePlayer.prepareToPlay()
moviePlayer.scalingMode = .AspectFill
videoContainer.addSubview(moviePlayer.view)
moviePlayer.play()
}
}
【问题讨论】:
标签: ios uiview mpmovieplayer