我想为我的主应用程序创建一种屏幕保护程序视频,如果用户在应用程序中某段时间处于非活动状态,我会触发屏幕保护程序视频。MPMoviePlayerController忽略输入
为此,我使用MPMoviePlayerController
播放全屏视频(本地磁盘)。这是一个循环(重复)视频,屏幕上没有控件(MPMovieControlStyleNone
)。
- (IBAction)playMovie:(id)sender {
NSURL *url;
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"Movie" ofType:@"m4v"];
if (moviePath)
{
url = [NSURL fileURLWithPath:moviePath];
}
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleNone;
_moviePlayer.repeatMode = MPMovieRepeatModeOne;
_moviePlayer.shouldAutoplay = YES;
_moviePlayer.scalingMode = MPMovieScalingModeFill;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:NO 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];
}
}
这个效果很好。
但我需要解决以下问题
- 输入取消视频播放(取消输入)
- 当我加倍视频水龙头,它会放大,这必须停止。
任何建设性的反馈是高度appriciated。
在此先感谢。
嗨ChrisH,感谢您的回复。我想我可以完成你的建议。但我想添加淡入/淡出屏幕保护程序(我没有提到这个问题,我的坏)。所以我选择了下面的答案(如果这对其他人有帮助,我会发布这些答案)。不过谢谢。 – hdsenevi 2015-03-20 17:03:48