- (void)playVideo:(NSString*)url
{
NSLog(@"play~");
if(![PlayUrl isEqualToString:url]){
playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
//playerViewController.moviePlayer.allowsAirPlay = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
PlayUrl=[url copy];
//-- add to view---
[self.view addSubview:playerViewController.view]; //sdl4.3使用正常
//[self presentModalViewController:playerViewController animated:YES]; // sdk5.0使用正常
}else{
playerViewController.view.hidden=NO;
}
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[player pause];
playerViewController.view.hidden=YES;//sdl4.3使用正常
//[self dismissModalViewControllerAnimated:YES]; // sdk5.0使用正常
}
-(IBAction) pressedbutton:(id)sender
{
NSLog(@"按到我了");
NSString *url;
switch ([sender tag]) {
case 1:
url = [[NSBundle mainBundle] pathForResource:@"张学友 - 明天我要嫁给你" ofType:@"mp4"];
break;
default:
url = [[NSBundle mainBundle] pathForResource:@"video-2012-01-15-16-48-36" ofType:@"mp4"];
break;
}
[self playVideo:url];
}
sdk4.3没问题,因为我需要重新打开保持原来的播放进度!
但在sdk5.0 就出现问题多了1个导航白条, 而且MPMoviePlayerViewController还不是全屏,看不到播放器的控制导航和快进等等、纠结!
用[self presentModalViewController:playerViewController animated:YES]; 白条问题和全屏问题都可以解决,
但是重新打开就是重新播放。 难道鱼和熊掌不能兼得?