IOS3.2以降を想定しています。コントロールを最初に非表示にして移動を再生するためのコマンドの適切なシーケンスは何ですか。映画の再生中に、ユーザーは画面にタグを付けてコントロールを表示するオプションがあります。
ありがとう!
私の(コントロールは非表示ではありません)コード:
- (void)playMovie
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Test" ofType:@"m4v"]];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieDone:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieState:)
name:MPMoviePlayerNowPlayingMovieDidChangeNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieReady:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullScreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
moviePlayer.controlStyle = MPMovieControlStyleDefault; // MPMovieControlStyleNone MPMovieControlStyleEmbedded MPMovieControlStyleFullscreen MPMovieControlStyleDefault
moviePlayer.scalingMode = MPMovieScalingModeAspectFill; // MPMovieScalingModeAspectFit MPMovieScalingModeAspectFill
}
}
- (void) movieReady:(NSNotification*)notification
{
MPMoviePlayerController *moviePlayer = [notification object];
if ([moviePlayer loadState] != MPMovieLoadStateUnknown) {
// Remove observer
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
// When tapping movie, status bar will appear, it shows up
// in portrait mode by default. Set orientation to landscape
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
// Add movie player as subview
[[self view] addSubview:[moviePlayer view]];
// Play the movie
[moviePlayer play];
[moviePlayer setFullscreen:YES animated:YES];
}
}
[更新] @ReinYemによって提案されたように、はるかに優れた解決策は、タイマーの代わりにMPMoviePlayerLoadStateDidChangeNotificationに依存することです。
実際、次の解決策はもう考慮されるべきではありません。
最初はcontrolStyle
プロパティをMPMovieControlStyleNone
に設定し、1秒後に[performSelector:withObject:afterDelay:1]
を使用してMPMovieControlStyleFullscreen
に設定します。それはうまく機能し、ユーザーがビデオをタップするまでコントロールは表示されません。
タイマーの代わりにコールバックを使用します:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hidecontrol)
name:MPMoviePlayerLoadStateDidChangeNotification
object:playerView.moviePlayer];
コールバック機能付き:
- (void) hidecontrol {
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerNowPlayingMovieDidChangeNotification object:playerView.moviePlayer];
[playerView.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
}
player.moviePlayer.controlStyle = MPMovieControlStyleNone;
それを行うための最新の方法です。 :)