MPMoviePlayerViewController和UIImagePickerController不在.mov中播放可听声音

时间:2015-08-17 16:50:04

标签: ios uiimagepickercontroller mpmovieplayercontroller

使用以下代码拍摄视频并保存到测试phone5 IOS-8.1。问题:当我使用UIImagePickerController上的播放按钮在点击"使用视频"之前查看视频时按钮声音转到\保存到听不见(可能是.5 out of 10max)。当我只需按下"使用视频"没有查看的按钮(不使用UIImagePickerController中的播放按钮)声音在正常级别播放。播放选项在普通的UIViewController上提供给用户两个视图。 -谢谢您的帮助。我错过了什么?

- (IBAction)takeVideo:(id)sender {
    NSLog(@"hello take vid");



    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIImagePickerController *picker = [[UIImagePickerController alloc]init];
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.delegate = self;
        picker.videoMaximumDuration = 4;
        picker.allowsEditing = NO;


        NSArray *mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeMovie, nil];

        picker.mediaTypes = mediaTypes;

        [self presentViewController:picker animated:NO completion:nil];






    } else {

        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"I'm afraid there's no camera on this device!" delegate:nil cancelButtonTitle:@"Dang!" otherButtonTitles:nil, nil];
        [alertView show];
    }


}

使用以下代码保存.mov

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    // user hit cancel
    [self dismissViewControllerAnimated:NO completion:nil];
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    // grab our movie URL
    NSURL *chosenMovie2 = [info objectForKey:UIImagePickerControllerMediaURL];


    NSString *fileURL2 = [self grabFilePath:[NSString stringWithFormat:@"%@%@", @"NewProfile", @"_V.mov"]];
    NSData *movieData2 = [NSData dataWithContentsOfURL:chosenMovie2];
    [movieData2 writeToFile:fileURL2 atomically:YES];

    // save it to the Camera Roll (option 2)
    UISaveVideoAtPathToSavedPhotosAlbum([chosenMovie2 path], nil, nil, nil);

    // and dismiss the picker
    [self dismissViewControllerAnimated:NO completion:nil];


}


- (NSURL*)grabFileURL:(NSString *)fileName {

    // find Documents directory
    NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];

    // append a file name to it
    documentsURL = [documentsURL URLByAppendingPathComponent:fileName];

    return documentsURL;
}

使用以下代码稍后在应用中播放视频

- (IBAction)btnPlayVideo:(id)sender {

    // new test

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *vidPic = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%@", self.emailID, @"_V.mov"]];
    /////

    NSLog(@"helo from btnPlayVideo");

    NSURL *video;
    NSString *vidPath;

    // create a movie player view controller

    // and to convert that back into a URL:
    NSURL *documentsURL = [NSURL fileURLWithPath:vidPath];

    MPMoviePlayerViewController * controller = [[MPMoviePlayerViewController alloc]initWithContentURL:documentsURL];
    [controller.moviePlayer prepareToPlay];
    [controller.moviePlayer play];

    // and present it
    [self presentMoviePlayerViewControllerAnimated:controller];


}

0 个答案:

没有答案