我用来播放视频的方法是:
-(void)playVideo:(NSString*)title {
NSLog(@"NAME: %@", title);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *moviePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4", title]];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
mp.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[self presentMoviePlayerViewControllerAnimated:mp];
[mp release];
}
视频停止大约4或5秒后,显示上一个屏幕,我收到以下错误:
_itemFailedToPlayToEnd: {
AVPlayerItemFailedToPlayToEndTimeErrorKey = "Error Domain=AVFoundationErrorDomain Code=-11800 \"The operation could not be completed\" UserInfo=0xb19a220 {NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0xb17fac0 \"The operation couldn\U2019t be completed. (OSStatus error -12551.)\", NSLocalizedFailureReason=An unknown error occurred (-12551)}";
答案 0 :(得分:0)
尝试简单步骤:
第1步:导入MediaPlayer框架
#import <MediaPlayer/MediaPlayer.h>
第2步:在.h文件中设置委托
UIViewController<MPMediaPlayback>
第3步:
- (void)viewDidLoad
{
[super viewDidLoad];
NSBundle *bundle = [NSBundle mainBundle];
NSString *fileLocation= [bundle pathForResource:@"file_video" ofType:@"m4v"];
NSURL *vedioURL =[NSURL fileURLWithPath:fileLocation];
MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:vedioURL];
[self presentMoviePlayerViewControllerAnimated:videoPlayerView];
[videoPlayerView.moviePlayer play];
}
-(void)endSeeking
{
[self.navigationController popViewControllerAnimated:NO];
}
-(void)stop
{
[self.navigationController popViewControllerAnimated:NO];
}
答案 1 :(得分:0)
尝试使用此代码一次:
-(void)playVideo
{
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:VideoURL]];
]
[self presentMoviePlayerViewControllerAnimated:mp];
[mp.moviePlayer play];
}
并确保