0

フォトアルバムから動画を取得して再生する例を教えてください。

次のコードが機能していません

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

1 に答える 1

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];
于 2012-04-05T07:05:38.730 に答える