2012-04-05 13 views
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]; 
+0

可能複製[写真からビデオにアクセスする方法アルバムとそれを再生?](http://stackoverflow.com/questions/10) 006312/how-to-access-videos-from-photo-album-and-play-them) – tipycalFlow

答えて

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]; 
+0

大丈夫ビデオを再生するためのコードを追加しました。私は自分のアプリからコピーしましたので、それが動作することを知っています – shabbirv

+0

私の質問を見てください私は編集しました – Shreedhar

+0

この行を追加してみてください "[self presentMoviePlayerViewControllerAnimated:moviePlayerController];" – shabbirv

関連する問題