我正在尝试使用 MPMoviePlayerViewController 播放视频,我展示了 MPMoviePlayerViewController,但 1 秒后他自己解散了。
这是我的代码:
。H:
#import <MediaPlayer/MediaPlayer.h>
@property (strong, nonatomic) MPMoviePlayerViewController *moviePlayerViewController;
米:
- (void)playmovie
{
NSString *databaseName = @"NO.mp4";
NSArray *documentPaths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [documentPaths objectAtIndex:0];
NSString *databasePath = [documentDir stringByAppendingPathComponent:databaseName];
NSURL *movieURL = [NSURL fileURLWithPath:databasePath];
UIGraphicsBeginImageContext(CGSizeMake(1,1));
self.moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:self.moviePlayerViewController];
UIGraphicsEndImageContext();
[self.moviePlayerViewController.moviePlayer prepareToPlay];
[self.moviePlayerViewController.moviePlayer play];
}
请告诉我我做错了什么。
提前致谢!