2013-07-02 30 views
0

我正在试图从lib中播放视频,但我不能弄清楚做什么我错了我已经尝试了许多东西,它没有显示任何类型的错误我的代码如下问题采摘视频和玩它

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

    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; 

    NSURL *url = [[NSURL alloc]initWithString:mediaType]; 

    NSLog(@"%@",url); 

    [self dismissModalViewControllerAnimated:NO]; 


    /* Create a new movie player object. */ 
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url]; 

    if (player) 
    { 
       /* Specify the URL that points to the movie file. */ 
     [player setContentURL:url]; 





     /* Add a background view as a subview to hide our other view controls 
     underneath during movie playback. */ 


     CGRect viewInsetRect = CGRectInset ([self.view bounds], 
              kMovieViewOffsetX, 
              kMovieViewOffsetY); 
     /* Inset the movie frame in the parent view frame. */ 
     [[player view] setFrame:viewInsetRect]; 

     [player view].backgroundColor = [UIColor lightGrayColor]; 

     /* To present a movie in your application, incorporate the view contained 
     in a movie player’s view property into your application’s view hierarchy. 
     Be sure to size the frame correctly. */ 
     [self.view addSubview: [player view]]; 


     [player setCurrentPlaybackRate:0.5]; 
     [player play]; 
    } 







     // Register for the playback finished notification 
     [[NSNotificationCenter defaultCenter] 
     addObserver: self 
     selector: @selector(myMovieFinishedCallback:) 
     name: MPMoviePlayerPlaybackDidFinishNotification 
     object: player]; 



} 



// When the movie is done, release the controller. 
-(void) myMovieFinishedCallback: (NSNotification*) aNotification 
{ 
    MPMoviePlayerController *playerr = [aNotification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification 
                object:playerr]; 
    [playerr stop]; 
    [self.view removeFromSuperview]; 
    [playerr autorelease]; 
} 

发生了什么是第一presetModelViewController越来越显示,然后我可以显示在我的lib中的视频,我可以选择其中之一,但是当我选择视频,然后它显示我的灰色视图,没有别的,我的视频没有播放。

如果你可以在我的代码中发现任何错误,并可以帮助我,那么这将是很大的帮助。

+0

,您可以发送的NSString * mediaType的的日志。 – spider1983

+0

让我向你展示 – java

+0

它打印public.movi​​e – java

回答

1

请通过下面的链接来帮助你解决你现有的问题和实施。

http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios

NSURL *videoURL = [NSURL URLWithString:videoURLString]; 
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] 
initWithContentURL:videoURL]; 
[moviePlayer prepareToPlay]; 
    [moviePlayer play]; 
    [self.view addSubview:moviePlayer.view]; 
+0

他们正在做MPMoviePlayerViewController这对我没有帮助,因为我想使用mpmoviecontroller的属性像放慢视频,播放视频速度和所有其他属性这就是为什么我需要使用这种方法 – java

+0

让我试着生病让你你发生什么 – java

+0

对不起,我没有看到你的整个代码我编辑了我的答案。 – spider1983

0
This is what solved my problem thanks to spider1983 

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

     [self dismissModalViewControllerAnimated: YES]; 
    } 

    // For responding to the user accepting a newly-captured picture or movie 
    - (void) imagePickerController: (UIImagePickerController *) picker 
    didFinishPickingMediaWithInfo: (NSDictionary *) info { 

     NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; 


     [self dismissModalViewControllerAnimated:NO]; 

     // Handle a movie capture 
     if (CFStringCompare ((__bridge_retained CFStringRef)mediaType, kUTTypeMovie, 0) 
      == kCFCompareEqualTo) { 

      NSString *moviePath = [[info objectForKey: 
            UIImagePickerControllerMediaURL] path]; 




      NSLog(@"%@",[info objectForKey: 
         UIImagePickerControllerMediaURL]); 


     /* Create a new movie player object. */ 




      MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[info objectForKey:UIImagePickerControllerMediaURL]]; 



     if (player) 
     { 
        /* Specify the URL that points to the movie file. */ 
      [player setContentURL:[info objectForKey: 
            UIImagePickerControllerMediaURL]]; 


      CGRect viewInsetRect = CGRectInset ([self.view bounds], 
               kMovieViewOffsetX, 
               kMovieViewOffsetY); 
      /* Inset the movie frame in the parent view frame. */ 
      [[player view] setFrame:viewInsetRect]; 

      [player view].backgroundColor = [UIColor lightGrayColor]; 

      /* To present a movie in your application, incorporate the view contained 
      in a movie player’s view property into your application’s view hierarchy. 
      Be sure to size the frame correctly. */ 
      [self.view addSubview: [player view]]; 



      [player prepareToPlay]; 
      [player setCurrentPlaybackRate:0.5]; 
      [player play]; 
     } 







      // Register for the playback finished notification 
      [[NSNotificationCenter defaultCenter] 
      addObserver: self 
      selector: @selector(myMovieFinishedCallback:) 
      name: MPMoviePlayerPlaybackDidFinishNotification 
      object: player]; 
     } 


    }