यहाँ एक संकलन और इसके बाद के संस्करण जवाब प्लस कुछ और विवरण की सफाई है पर एक नजर है।
(0) सुनिश्चित करें कि आपके पास इन दोनों शामिल हैं। UINavigationControllerDelegate और UIImagePickerControllerDelegate:
#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h> // needed for video types
(1) अपने ज फाइल करने के लिए दो प्रतिनिधियों को जोड़ें। हमारे लिए, यह इस तरह दिखता है:
@interface ATHViewController() <UITabBarDelegate, UINavigationControllerDelegate,UIImagePickerControllerDelegate>
(2) उपयोगकर्ता को अपनी लाइब्रेरी से वीडियो की पसंद के साथ प्रस्तुत करें। इस कोड को अपनी .m फ़ाइल में कहीं भी जोड़ें।
// Present videos from which to choose
UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
videoPicker.delegate = self; // ensure you set the delegate so when a video is chosen the right method can be called
videoPicker.modalPresentationStyle = UIModalPresentationCurrentContext;
// This code ensures only videos are shown to the end user
videoPicker.mediaTypes = @[(NSString*)kUTTypeMovie, (NSString*)kUTTypeAVIMovie, (NSString*)kUTTypeVideo, (NSString*)kUTTypeMPEG4];
videoPicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
[self presentViewController:videoPicker animated:YES completion:nil];
(3) पिकर से प्रतिक्रियाओं को संभालें। इस कोड को अपने प्रतिनिधि वर्ग में जोड़ें।
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// This is the NSURL of the video object
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(@"VideoURL = %@", videoURL);
[picker dismissViewControllerAnimated:YES completion:NULL];
}
(4) जब उपयोगकर्ता कुछ भी चुनने में विफल रहता है तो संभाल लें। [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypePhotoLibrary]
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
https://github.com/questbeat/QBImagePicker आप 'videoPicker.mediaTypes = तरह – kb920
सेट mediaTypes मदद कर सकता हो;' और अपने कोड निष्पादित करने के लिए प्रयास करें। – VRAwesome