我正在尝试使用MPMoviePlayerViewController播放视频,我提供了MPMoviePlayerViewController,但在1秒后他就解雇了。
这是我的代码:
·H:
#import <MediaPlayer/MediaPlayer.h>
@property (strong, nonatomic) MPMoviePlayerViewController *moviePlayerViewController;
的.m:
- (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];
}
请告诉我我做错了什么。
提前致谢!
答案 0 :(得分:3)
检查以下答案
https://stackoverflow.com/a/15586468/1713478
将网址更改为以下代码
NSString *path =[[NSBundle mainBundle] pathForResource:@"NO" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
试试这个你会成功。
答案 1 :(得分:0)
试试这个..
NSString *databaseName = @"NO.mp4";
NSArray *documentPaths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [documentPaths objectAtIndex:0];
NSString *databasePath = [documentDir stringByAppendingPathComponent:databaseName];
NSURL *url = [NSURL fileURLWithPath:databasePath];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
moviePlayer.view.frame = CGRectMake(0, 0, 500, 500);
moviePlayer.moviePlayer.shouldAutoplay=YES;
moviePlayer.moviePlayer.controlStyle = MPMediaTypeMusicVideo;
[moviePlayer.moviePlayer setFullscreen:YES animated:YES];
[self.view addSubview:moviePlayer.view];
[moviePlayer.moviePlayer play];