如何从相册和播放中获取视频

时间:2012-04-05 06:56:57

标签: iphone ios xcode

请帮我一个从相册和游戏中获取视频的示例。

以下代码无效

NSURL *URL = [info objectForKey:UIImagePickerControllerMediaURL];
  MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:aurl];
        [self.view addSubview:moviePlayerController.view];
        moviePlayerController.useApplicationAudioSession = NO;
        moviePlayerController.fullscreen = YES;
        [moviePlayerController play];

1 个答案:

答案 0 :(得分:1)

 // Choose video from library                   
                        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
                        imagePicker.delegate = self;
                        imagePicker.mediaTypes =
                        [UIImagePickerController availableMediaTypesForSourceType:
                         imagePicker.sourceType];
                        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                        [self presentModalViewController:imagePicker animated:YES];
                        [imagePicker release];

//获取视频

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissModalViewControllerAnimated:YES];

    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if ([mediaType isEqualToString:@"public.image"]){
        NSLog(@"found an image");
    }
    else if ([mediaType isEqualToString:@"public.movie"]){
        NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
        NSLog(@"found a video");
        NSData *webData = [NSData dataWithContentsOfURL:videoURL];
       }

}

//播放视频

MPMoviePlayerViewController *movie = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self.view addSubview:movie.view];
[self presentMoviePlayerViewControllerAnimated:movie];
[movie release];
相关问题