- (void)viewDidLoad
{
[super viewDidLoad];
MPMoviePlayerController *player;
NSLog(@"%@",gotVideo);
NSURL *urlString=[NSURL URLWithString:gotVideo];
player = [[MPMoviePlayerController alloc] initWithContentURL:urlString];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
//---play movie---
[player play];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
}
在iOS 7.1模拟器中,视频无法播放。请提供任何建议。
答案 0 :(得分:0)
您忘了展示或添加为子视图
[self presentMoviePlayerViewControllerAnimated:player];
//---play movie---
[player play];
答案 1 :(得分:0)
试用此代码
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *urlString=[NSURL URLWithString: urlString];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: urlString];
[player.view setFrame:CGRectMake(//set rect frame)];
player.controlStyle = MPMovieControlStyleDefault;
player.shouldAutoplay=YES;
player.repeatMode = NO;
[player setFullscreen:YES animated:NO];
[player prepareToPlay];
[player play];
[self.view addsubview: player.view];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
}