2015-11-20 179 views
-7

我嘗試在屏幕中顯示加載的視頻。我have't使用SWIFT before.I馬新swift.Here一些代碼的目標C將此代碼轉換爲swift

- (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]; 

    } 

如何迅速轉換。我用videoURL,Videocontroller像這樣迅速

var videoPlayer = MPMoviePlayerController() 

而對於videoURL我用let videoURL = info[UIImagePickerControllerMediaURL]

不過,雖然使用我不知道如何轉換的所有代碼,請幫忙convrt我的目標C代碼swift2.0 .Thanks

我這樣做對:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){ 

     let videoURL = info[UIImagePickerControllerMediaURL] 



    } 

剩下的代碼我現在不如何的Alloc爲的MPMoviePlayerController和所以在代碼

回答

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() 

    } 
+0

感謝您的代碼。爲'self.videoURL'如何聲明我的意思是初始化。 lIke'videoUrl'在目標c中是'@property(強,非原子)NSURL * videoURL;'。如何做到這一行代碼'快速' – 2131

+0

這個鏈接[http://stackoverflow.com/questions/24014800/property-synthesize-equivalent-in-swift]可能會幫助你詳細。 – byJeevan

相關問題