我正在开发应用程序,该应用程序在 ios 设备上执行时运行良好,但在 Android 设备中播放从应用程序上传的视频时,不支持 .mov 格式。
我的代码可以正常工作,但需要 .mp4 格式的视频
-(void)openLibrary
{
cameraUI = [[UIImagePickerController alloc] init];
[cameraUI setDelegate:self];
[cameraUI setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[cameraUI setAllowsEditing:YES];
cameraUI.tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
[self presentViewController:cameraUI animated:YES completion:nil];
}
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose movie capture
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
[controller presentViewController:cameraUI animated:YES completion:nil];
return YES;
}
- (void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
// Handle a movie capture
if (CFStringCompare (( CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
NSUserDefaults *def =[NSUserDefaults standardUserDefaults];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
videoPath =[NSString stringWithFormat:@"%@/xyz.mov",docDir];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
{
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
[videoData writeToFile:videoPath atomically:NO];
[def setValue:videoPath forKey:@"videoPath"];
}
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[info objectForKey:UIImagePickerControllerMediaURL]];
CMTime duration = playerItem.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(@"seconds : %f",seconds);
if (seconds > 10) {
[def removeObjectForKey:@"videoPath"];
_lblVideo.hidden = TRUE;
[self.view makeToast:@"Select video which is less than 10 seconds" duration:2.0 position:@"center"];
}
else
{
_lblVideo.hidden = FALSE;
NSLog(@"Length is not greater than 10");
[self.view makeToast:@"Word is ready for posting" duration:2.0 position:@"center"];
}
}
}
好吧,我正在寻找一个好的解决方案,而不是根本不起作用的扩展更改解决方案。