我尝试在屏幕上显示已加载的视频。我之前没有使用过swift。我是swift的新手。在目标c中有一些代码
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
self.videoURL = info[UIImagePickerControllerMediaURL];
[picker dismissViewControllerAnimated:YES completion:NULL];
self.videoController = [[MPMoviePlayerController alloc] init];
[self.videoController setContentURL:self.videoURL];
[self.videoController.view setFrame:CGRectMake (0, 0, self.view.frame.size.width, 460)];
[self.view addSubview:self.videoController.view];
[self.videoController play];
}
如何在swift中转换。我在swift中使用videoURL,Videocontroller
这样的
var videoPlayer = MPMoviePlayerController()
videoURL
使用了let videoURL = info[UIImagePickerControllerMediaURL]
但是虽然使用我不知道如何转换所有代码,请帮助我将目标c代码转换为swift2.0。谢谢
我是这样做的:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){
let videoURL = info[UIImagePickerControllerMediaURL]
}
剩下的代码我现在不知道如何为Mpmovieplayercontroller等代码分配
答案 0 :(得分:1)
您在swift中的完整代码。
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: Dictionary) {
self.videoURL = info[UIImagePickerControllerMediaURL]
picker.dismissViewControllerAnimated(true, completion: nil)
self.videoController = MPMoviePlayerController()
self.videoController.contentURL = self.videoURL
self.videoController.view.frame = CGRectMake(0,0,self.view.frame.size.width,460)
self.view.addSubview(self.videoController.view)
self.videoController.play()
}