-7

I am try to display the loaded video in screen. i have't use swift before.I ma new to swift.Here some code in objective 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];

   }

How to convert in swift. i used videoURL,Videocontroller like this in swift

var videoPlayer = MPMoviePlayerController()

And for videoURL i used let videoURL = info[UIImagePickerControllerMediaURL]

But while use i dont know how to convert all code, please help to convrt my objective c code to swift2.0 .Thanks

i did so for :

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

        let videoURL = info[UIImagePickerControllerMediaURL]



    }

Remaining code i dont now how to alloc for Mpmovieplayercontroller and so on code

2131
  • 93
  • 1
  • 10

1 Answers1

1

Your complete code in 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()

    }
byJeevan
  • 3,728
  • 3
  • 37
  • 60
  • thanks for your code. for `self.videoURL` how to declare that i means to initialise that . lIke that `videoUrl` is in objective c is `@property (strong, nonatomic) NSURL *videoURL;` . How to do this line code to `swift` – 2131 Nov 20 '15 at 11:34
  • This link[http://stackoverflow.com/questions/24014800/property-synthesize-equivalent-in-swift] might help you in detail. – byJeevan Nov 20 '15 at 11:42