在我的应用程序中,我想使用 UIImagePickerController 从库中选择视频。但是当我选择持续时间超过 5 分钟的视频时,我的应用程序在 ipod 上崩溃了。我如何限制用户选择持续时间超过 5 分钟的视频。请给我这个错误的解决方案。谢谢你。
问问题
692 次
3 回答
1
试试这个:
NSURL * aUrlMovie = [[信息 valueForKey:UIImagePickerControllerMediaURL] 保留];/ AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:aURLPath]; CMTime 持续时间 = playerItem.duration; 浮点秒 = CMTimeGetSeconds(duration);
然后为您希望的秒数添加验证..
于 2012-06-15T06:38:54.090 回答
1
#pragma mark UIImagePickerController delegate
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ( [mediaType isEqualToString:(NSString*)kUTTypeMovie] ) {
self.mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
if ( UIVideoAtPathIsCompatibleWithSavedPhotosAlbum( mediaPath ) ) {
UISaveVideoAtPathToSavedPhotosAlbum( mediaPath,
self,
@selector(video:didFinishSavingWithError:contextInfo:),
NULL );
}
}
[self dismissModalViewControllerAnimated:YES];
}
于 2012-06-15T08:48:59.293 回答
1
试试这个picker.videoMaximumDuration = 5;
像这样的东西:
#import <AVFoundation/AVFoundation.h>
#import <AVFoundation/AVAsset.h>
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *selectedVideoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:selectedVideoUrl];
CMTime duration = playerItem.duration;
float seconds = CMTimeGetSeconds(duration);
//NSLog(@"duration: %.2f", seconds);
if(seconds > 300)
{
[picker popViewControllerAnimated:YES];
}
else{
[picker dismissModalViewControllerAnimated:YES];
}
}
于 2012-06-15T08:58:22.377 回答