MPMoviePlayerViewController auto dismiss issue

Nearby,need to do a project about MPMoviePlayerViewController and caught a very strange issue:

When I call 

presentMoviePlayerViewControllerAnimated:
the MoviePlayerViewController can appear normally,but after 1~2 seconds,it will auto dismiss.

The original code is:

UITableViewCell *cell = [tableView cellForRowAtIndexPath: indexPath];
    NSString *videoPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent: cell.textLabel.text];
    NSURL *videoUrl = [NSURL URLWithString: videoPath];//different
//    NSURL *videoUrl = [NSURL fileURLWithPath: videoPath];
    
    UIGraphicsBeginImageContext(CGSizeMake(1,1));
    MPMoviePlayerViewController *playerView = [[MPMoviePlayerViewController alloc] initWithContentURL: videoUrl];
    UIGraphicsEndImageContext();
    [self presentMoviePlayerViewControllerAnimated: playerView];
    [playerView release];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finishPlay:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
When I search for this issue,I have found many programmer has caught this issue before,but I have not found the way to fix this issue.

At last I have found the way to fix this issue,the link:

http://stackoverflow.com/questions/8612636/iphone-mpmovieplayercontroller-dismiss-itself-before-playing-video

only need to change one line code,the issue can be fixed.

It is using 

NSURL *videoUrl = [NSURL fileURLWithPath: videoPath];

to replace the code:

NSURL *videoUrl = [NSURL URLWithString: videoPath];
it will be okay.

Thanks,

Blues




你可能感兴趣的:(MPMoviePlayerViewController auto dismiss issue)