我使用MPMoviePlayerController从互联网上播放视频。
player = [player initWithContentURL:[NSURL URLWithString:videoURL]];
player.view.frame = CGRectMake(0, 0, videoView.frame.size.width, videoView.frame.size.height - 20);
[player setControlStyle:MPMovieControlStyleEmbedded];
player.scalingMode = MPMovieScalingModeAspectFit;
[player prepareToPlay];
player.shouldAutoplay = NO;
[videoView addSubview:player.view];
我通知说,在我点击全屏按钮(2箭头按钮)后,我被导航到全尺寸视频屏幕。我无法通过触摸"完成"按钮来恢复屏幕。我甚至使用了NSNotification,但无法解决问题。这是通知代码:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieEventFullscreenHandler:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieEventFullscreenHandler:)
name:MPMoviePlayerDidEnterFullscreenNotification
object:nil];
}
- (void)movieEventFullscreenHandler:(NSNotification*)notification {
[player setFullscreen:NO animated:NO];
[player setControlStyle:MPMovieControlStyleEmbedded];
}
如何通过触摸"完成"按钮来关闭视频屏幕?谢谢大家。
您可以使用MPMoviePlayerPlaybackDidFinishNotification的通知来观察完成按钮。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playObserver:)name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
然后,做出辞职的判断。
- (void) playObserver:(NSNotification *)notification
{
MPMoviePlayerController* player = moviePlayerView.moviePlayer;
if (player == [notification object]) {
if (_invalidVideoCount > MOVIE_TRY_TIMES) {
[self dismissViewController];
}
_invalidVideoCount++;
int reason = [[[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
//Whether continuous playback
if (![SINGLETON_CALL(SystemInfoManager) boolValueForKey:UserContinuousPlayEnableKey]) {
[self playFinishWithForce:YES];
return;
}
switch (reason) {
case MPMovieFinishReasonUserExited:
[self playFinishWithForce:YES];
break;
case MPMovieFinishReasonPlaybackError:
[self playFinishWithForce:YES];
break;
case MPMovieFinishReasonPlaybackEnded:
movieTryTimes = 0;
[self playFinishWithForce:NO];
break;
default:
break;
}
}
}
最后一个。
- (void)playFinishWithForce:(BOOL)force
{
FileInfoItem *item = ARRAY_OBJECT_AT_INDEX(_playlist, _currentIndex);
BOOL quit = force || !item;
if (quit) {
[self dismissViewController];
} else {
[self playMovieWithItem:item];
}
}
此外,您还可以使用MPMoviePlayerPlaybackStateDidChangeNotification的通知进行任何观察。有关详细信息,请参阅MPMoviePlayerController.h或https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html
我发现了问题。这就是我在视图中放置了[玩家停止]WillDisAppear,所以无法处理通知。我通过将其更改为[播放器暂停]来修复临时问题。我感谢你的任何帮助。