While using iphone PhotoLibrary, Restrict user to select any video file more than duration of 60secs?
Is there any method available to check video file duration as soon as user select Video from iPhone photo library ? And restrict user to select if开发者_运维问答 that video file is more than 60secs
imagePickerController.videoMaximumDuration = 60.0f;
// limits video length to 60 seconds.
where imagePickerController is object of UIImagePickerController.
Using videoMaximumDuration method you can restrict length of video from both ways. Like if you are recording video an alert will popup saying you cannot record video more than 60 sec and if you are selecting any video file from your library, first it will check the length of your video if length is more than 60 sec. Again alert will popup saying video is larger than 60 sec but there will be two options i.e. use or cancel. If you select use then it will crop the length of video upto 60sec from the beginning.
videoMaximumDuration method alert you as soon as 60 sec reached
There is no way to filter assets using the UIImagePicker
. However, using the new Asset Library Frameworks, you can fairly easily create your own video picker that filters videos based on your criteria.
For a good head start on doing this, here is a github repository that has recreated the UIImagePicker functionality using the Asset Library Frameworks: https://github.com/elc/ELCImagePickerController . You'll also want to look at the documentation for the ALAssetsFilter
for setting up filter criteria.
Here is a video demoing the control: http://vimeo.com/15666311
And here is his blog where he talks a bit about the control: http://www.icodeblog.com/2010/10/07/cloning-uiimagepickercontroller-using-the-assets-library-framework/
Cheers!
self.durationLabel.text = [NSString stringWithFormat:"Duration: %f",(float) self.player.duration]
And ultimately output:
self.durationLabel.text = [NSString stringWithFormat:@"Running Time: %d min",(int) ceil(self.player.duration/60)];
From the IPhone SDK Application Development: Building Applications for the AppStore
You can also read the duration of the sample (in seconds) through the
duration
property. This, too, is represented as anNSTimeInterval
, which is typed to a double floating-point:NSTimeInterval duration = player.duration
精彩评论