2012-04-04 6 views

Antwort

1

mit dem Code zu überprüfen, ob das Bild oder Video ist:

NSString *mediaType1 = [info objectForKey:UIImagePickerControllerMediaType]; 
    NSLog(@"mediaType : %@",mediaType1); 

    if ([mediaType1 isEqualToString:@"public.image"]) 
    { 
     //Show Image 
} 
else 
{ 
    //show Video 
} 

um das Video abzuspielen, die URL überprüfen.

EDIT:

 NSString *moviePath = [bundle pathForResource:@"IMG_0017" ofType:@"MOV"]; 
     NSLog(@"moviePath : %@",moviePath); 
    // NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain]; 

     NSURL *movieURL = [NSURL URLWithString:strValURL]; 
     NSLog(@"movieURL : %@",movieURL); 
     if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) 
     { 
      NSLog(@"> 3.2"); 
      MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL]; 
      if (mp) 
      { 
       [self presentMoviePlayerViewControllerAnimated:mp]; 
       mp.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 
       [mp.moviePlayer play]; 
       [mp release]; 
      } 
     } 
     else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) 
     { 
      NSLog(@"< 3.2"); 
      theMovie = [[MPMoviePlayerController alloc] initWithContentURL: movieURL]; 
      theMovie.scalingMode = MPMovieScalingModeAspectFill; 
      [[NSNotificationCenter defaultCenter] 
      addObserver: self 
      selector: @selector(myMovieFinishedCallback:) 
      name: MPMoviePlayerPlaybackDidFinishNotification 
      object: theMovie]; 
      [theMovie play]; 
     } 

- (void) moviePlayBackDidFinish:(NSNotification*)notification 
{ 
    MPMoviePlayerViewController *moviePlayer = [notification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                name:MPMoviePlayerPlaybackDidFinishNotification 
                object:moviePlayer]; 
    [moviePlayer release]; 
    [self.navigationController setNavigationBarHidden:NO animated:YES]; 
} 

- (void) movieFinishedCallback:(NSNotification*) aNotification 
{ 
    MPMoviePlayerController *player = [aNotification object]; 
    [[NSNotificationCenter defaultCenter] 
    removeObserver:self 
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:player]; 
    [player autorelease]; 
} 
+0

Ich weiß, wie man es überprüft .. Ich möchte, wenn es Video ist, wie man es spielt – Shreedhar

+0

dafür habe ich die URL gegeben. Prüfen Sie. – Sarah

1

In Ihrem - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info Methode können Sie die URL des Videos bekommen, und es spielen:

@property (nonatomic,retain) MPMoviePlayerController *moviePlayerController; 

if ([mediaType isEqualToString:@"public.movie"]) 
{ 
    NSURL *aURL = [info objectForKey:UIImagePickerControllerMediaURL];//get the url 
    // and init the video player using this url 
    _moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:aURL]; 
    [self.view _moviePlayerController.view]; 
    _moviePlayerController.useApplicationAudioSession = NO; 
    _moviePlayerController.fullscreen = YES; 
    [_moviePlayerController play]; 
} 

Natürlich werden Sie die MediaPlayer.framework importieren müssen

EDIT: Eine Mehrheit der Cocoa-Projekte verwenden jetzt arc, so dass der obige Code erfordert, dass Sie die MPMoviePlayerController Instanz selbst behalten (wie in this answer erwähnt).

+0

Es spielt kein Video – Shreedhar

+0

@Shreedhar Ich habe dies in der '- (void) imagePickerController: (UIImagePickerController *) Picker didFinishPickingMediaWithInfo: (NSDictionary *) info' Methode. – tipycalFlow

+0

Funktioniert nicht ... – c0d3Junk13

Verwandte Themen