我想爲我的主應用程序創建一種屏幕保護程序視頻,如果用戶在應用程序中某段時間處於非活動狀態,我會觸發屏幕保護程序視頻。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