我使用MPMoviePlayerController播放视频,但这只显示黑屏。没有播放我的视频。这段代码是对的。哪里可能我错了....
我已经完成了这段代码来播放视频..
NSString * str=[[NSBundle mainBundle]pathForResource:@"iGreet" ofType:@"m4v"];
NSURL * url=[NSURL fileURLWithPath:str];
MPMoviePlayerController * movieController=[[MPMoviePlayerController alloc]initWithContentURL:url];
movieController.controlStyle=MPMovieControlStyleFullscreen;
[movieController.view setFrame:self.view.bounds];
[self.view addSubview:movieController.view];
[movieController prepareToPlay];
[movieController play];
任何帮助表示赞赏.. 提前谢谢..
答案 0 :(得分:9)
如果您尝试从资源播放视频,则需要提及:
[movieController setMovieSourceType:MPMovieSourceTypeFile];
答案 1 :(得分:1)
这是我的代码。我有一个按钮,可以为我的视频显示图像。
@property (nonatomic,strong) MPMoviePlayerController* moviePlayer;
将此添加到您的.h文件中。
NSURL * url = [NSURL URLWithString: @ “http://www.mydomain/video/1.mp4”];
_moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
CGRect frame = _btnVideo.frame;
[_moviePlayer.view setFrame:frame];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:NO animated:YES];
答案 2 :(得分:0)
根据documentation,未提及.m4v扩展名。
答案 3 :(得分:0)
我确实喜欢这个并且工作正常:
NSString *videoFileName = [[NSBundle mainBundle] pathForResource:videoName ofType:@"m4v" inDirectory:nil];
self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath:videoFileName]];
[self.moviePlayerController setShouldAutoplay:YES];
[self.moviePlayerController prepareToPlay];
[self.moviePlayerController setFullscreen:NO];
[self.moviePlayerController.view setFrame:self.infoViewController.view.bounds];
[self.view addSubview:self.moviePlayerController.view];
[self.moviePlayerController play];