I am trying to allow users to upload video to there profile. Users are able to choose videos from there phone but after clicking the choose button of the video, the app crashes and you get a fatal error: unexpectedly found nil while unwrapping an Optional value (lldb).
This is my code:
var objMoviePlayerController: MPMoviePlayerController = MPMoviePlayerController()
var urlVideo :NSURL = NSURL()
@IBOutlet weak var videoprofileView: UIImageView!
@IBOutlet weak var addvideoBtn: UIButton!
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject])
{
urlVideo = (info as NSDictionary).objectForKey(UIImagePickerControllerOriginalImage) as! NSURL
self.dismissViewControllerAnimated(true, completion: nil)
objMoviePlayerController = MPMoviePlayerController(contentURL: urlVideo)
objMoviePlayerController.movieSourceType = MPMovieSourceType.Unknown
objMoviePlayerController.view.frame = self.videoprofileView.bounds
objMoviePlayerController.scalingMode = MPMovieScalingMode.AspectFill
objMoviePlayerController.controlStyle = MPMovieControlStyle.Embedded
objMoviePlayerController.shouldAutoplay = true
videoprofileView.addSubview(objMoviePlayerController.view)
objMoviePlayerController.prepareToPlay()
objMoviePlayerController.play()
}
I receive a thread 1 exc_bad_instruction (code=exc_i386_invop subcode=0x0) error from this line of code:
urlVideo = (info as NSDictionary).objectForKey(UIImagePickerControllerOriginalImage) as! NSURL
Is there any way someone can help? Thank you!