2014-09-17 2 views
0
-(void)playVideo 
{ 
    NSURL *vedioURL; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil]; 
    NSLog(@"files array %@", filePathsArray); 

    NSString *fullpath; 

    for (NSString *apath in filePathsArray) 
    { 
     fullpath = [documentsDirectory stringByAppendingPathComponent:apath]; 
     vedioURL =[NSURL fileURLWithPath:fullpath]; 
    } 
    NSLog(@"vurl %@",vedioURL); 

    moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:vedioURL]; 
    [self.view addSubview:moviePlayer.view]; 
    [moviePlayer.moviePlayer prepareToPlay]; 
    [moviePlayer.view setFrame:self.view.bounds]; // player's frame must match parent's 
    //moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown; 

    moviePlayer.moviePlayer.fullscreen = YES; 
    [moviePlayer.moviePlayer play]; 
    [self.view bringSubviewToFront:btnSkip]; 
// [[NSNotificationCenter defaultCenter] addObserver:self 
//            selector:@selector(movieFinishedCallback:) 
//             name:MPMoviePlayerPlaybackDidFinishNotification 
//            object:moviePlayer]; 


} 

얻기에게 다음과 같은 오류itemFailedToPlayToEnd 오류 .H 파일에 비디오

_itemFailedToPlayToEnd: { kind = 1; new = 2; old = 0; } error in iOS while playing video 
+0

동영상 파일을 가지고 있습니까? 동영상을 재생할 수 없다는 AVPlayerItemStatus가 표시되는 것 같습니다. – Sandeep

+0

예 비디오가 있으며이 NSLog (@ "vurl % @", vedioURL)에서 로컬 경로를 얻고 있습니다. – Seema

답변

0

을 재생하는 동안은하는 .m 파일

에서

MPMoviePlayerController * 플레이어

으로 새 인스턴스를 만들

- (void) playMovieOffline:(UIView *)view 
    { 

     // Register to receive a notification when the movie has finished playing. 
     NSString *path = [[NSBundle mainBundle]pathForResource: 
          @"videofile_name" ofType:@"mp4"]; 
     player = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:path]]; 

     [[NSNotificationCenter defaultCenter] addObserver:self 
               selector:@selector(moviePlayerDidFinish:) 
                name:MPMoviePlayerPlaybackDidFinishNotification 
                object:player]; 

     [player setControlStyle:MPMovieControlStyleNone]; 
     player.movieSourceType = MPMovieSourceTypeFile; 
     [player play]; 
     [player.view setFrame:CGRectMake(0, 0, 320, 235)]; 
     [view addSubview:player.view]; 
    } 
    - (void)moviePlayerDidFinish:(NSNotification *)note 
    { 
     if (note.object == player) { 
      NSInteger reason = [[note.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue]; 
      if (reason == MPMovieFinishReasonPlaybackEnded) 
      { 
       [player play]; 
      } 
     } 
    } 

시도해주세요. 도움이 되었으면 좋겠습니다.

관련 문제