我正在将应用程序从iOS6移植到iOS7。有一个奇怪的问题,在完成按钮调用后屏幕变黑。我试过了this,this和this。
没有合适的答案,理论上我觉得使用以前的方法不会有任何问题。
请告诉我为什么会出现这个问题。
由于
答案 0 :(得分:1)
这可以提供帮助 在.h文件中导入MediaPlayer
#import <MediaPlayer/MediaPlayer.h>
制作一个属性
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
之后你可以通过这个播放视频
-(void)playMovie:(id)sender
{
NSURL *url = [NSURL URLWithString:
@"http://www.xyz.com/ios_book/movie/movie.mov"];
_moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
}
在删除视频视图后,添加此
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
答案 1 :(得分:-1)
在主窗口上添加电影播放器控制器视图,如:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:@"map.mp4"]];
[player prepareToPlay];
[player.view setFrame: self.view.bounds];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.window addSubview: player.view];
[player play];
希望这对你有用!
答案 2 :(得分:-2)
试试这种方式..
<强> ViewController.m 强>
MPMoviePlayerViewController *mp=[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:[[arr_videos objectAtIndex:indexPath.row]valueForKey:@"Video_path"]]];
MPMoviePlayerController *pc=[mp moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self presentViewController:mp animated:YES completion:nil];
[pc prepareToPlay];
[pc play];