我正在开发应用程序,并且应用程序在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"];
}
}
}
我正在寻找一个好的解决方案,而不是根本不起作用的扩展更改解决方案。
答案 0 :(得分:0)
当您保存录制的视频时,请手动更改.mp4,如下所示
//你的loaca目录
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString* mp4FilePath = [docsDir stringByAppendingPathComponent:@"recordedVideo.mp4"];