iphone – 在iOS 3.2(iPad)中正确显示和关闭全屏MPMoviePlayerController

iphone – 在iOS 3.2(iPad)中正确显示和关闭全屏MPMoviePlayerController,第1张

概述我的iPad应用程序中显示全屏电影时遇到很多麻烦,然后允许用户使用播放器控件上的完成按钮或“未全屏”按钮关闭它。 最初我正在使用MPMoviePlayerViewController进行电影演示,但是我没有从MPMoviePlayerController对象接收到进入/退出全屏通知,所以我转而自己做。 我可以使电影出现全屏(虽然过渡是janky),但是当按下“完成”或“非全屏”按钮时,播放器不采取 我的iPad应用程序中显示全屏电影时遇到很多麻烦,然后允许用户使用播放器控件上的完成按钮或“未全屏”按钮关闭它。

最初我正在使用MPMovIEPlayerVIEwController进行电影演示,但是我没有从MPMovIEPlayerController对象接收到进入/退出全屏通知,所以我转而自己做。

我可以使电影出现全屏(虽然过渡是janky),但是当按下“完成”或“非全屏”按钮时,播放器不采取任何 *** 作。我已经发布了我的代码如下:

- (voID)startPlayingMovIEWithURLString:(Nsstring *)movIEURLString {    // I get all of these callbacks **EXCEPT** the "willExitFullScreen:" callback.    [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(willEnterFullScreen:) name:MPMovIEPlayerWillEnterFullscreenNotification object:nil];    [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(willExitFullScreen:) name:MPMovIEPlayerWillExitFullscreenNotification object:nil];    [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(dIDFinishPlayback:) name:MPMovIEPlayerPlaybackDIDFinishNotification object:nil];    [self.movIEPlayerController setContentURL:someExistingURL];        // "self" is a UIVIEwController subclass,and is presented as a "fullscreen" modal vIEw controller from its parent        // I'm setting the movIE player's vIEw's frame to take up the full rectangle of my vIEw controller,but really I want the movIE to be completely removed when the user presses "done" (that is,removed from the vIEw hIErarchy). Not sure when/where to do this.    self.movIEPlayerController.vIEw.frame = self.vIEw.frame;    [self.vIEw addSubvIEw:self.movIEPlayerController.vIEw];    [self.movIEPlayerController setFullscreen:YES animated:YES];}

这里是我的dIDFinish回调的代码

- (voID)dIDFinishPlayback:(NSNotification *)notification {        // This ends up recursively telling the player that playback ended,thus calling this method,thus…well you get the picture.        // What I'm trying to do here is just make the player go away and show my old UI again.    [self.movIEPlayerController setFullscreen:NO animated:YES];}

所以显然我做错了事情,但我一直在上下文档,我无法弄明白如何让电影走开。我认为这会比这更直观。我究竟做错了什么?

解决方法 事件如何 – >通知工作:

>用户按“完成”按钮

> MPMovIEPlayerWillExitFullscreenNotification
> MPMovIEPlayerDIDExitFullscreenNotification

>用户在运输时按“离开全屏”按钮

> MPMovIEPlayerWillExitFullscreenNotification
> MPMovIEPlayerDIDExitFullscreenNotification
>请注意,播放不会停止

>电影到达

> MPMovIEPlayerPlaybackDIDFinish使用MPMovIEPlayerPlaybackDIDFinishReasonUserInfoKey设置为MPMovIEFinishReasonPlaybackEnded
>如果您从此通知中调用setFullscreen:否动画:您的MovIEPlayerController实例上的YES,那么您将获得WillExit和DIDExit通知。
>请注意,当用户按完成或离开全屏按钮时,您不会收到播放清除通知。

所以,通常,如果你想摆脱MovIEPlayer的视图,你需要将[self.movi​​ePlayerController.vIEw removeFromSupervIEw]放在DIDExitFullscreen通知处理程序中。 WillExitFullscreen太早了

这里是我的代码:

- (voID)willEnterFullscreen:(NSNotification*)notification {    NSLog(@"willEnterFullscreen");}- (voID)enteredFullscreen:(NSNotification*)notification {    NSLog(@"enteredFullscreen");}- (voID)willExitFullscreen:(NSNotification*)notification {    NSLog(@"willExitFullscreen");}- (voID)exitedFullscreen:(NSNotification*)notification {    NSLog(@"exitedFullscreen");    [self.movIEController.vIEw removeFromSupervIEw];    self.movIEController = nil;    [[NSNotificationCenter defaultCenter] removeObserver:self];}- (voID)playbackFinished:(NSNotification*)notification {    NSNumber* reason = [[notification userInfo] objectForKey:MPMovIEPlayerPlaybackDIDFinishReasonUserInfoKey];    switch ([reason intValue]) {        case MPMovIEFinishReasonPlaybackEnded:            NSLog(@"playbackFinished. Reason: Playback Ended");                         break;        case MPMovIEFinishReasonPlaybackerror:            NSLog(@"playbackFinished. Reason: Playback Error");                break;        case MPMovIEFinishReasonUserExited:            NSLog(@"playbackFinished. Reason: User Exited");                break;        default:            break;    }    [self.movIEController setFullscreen:NO animated:YES];}- (voID)showMovIE {    [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(willEnterFullscreen:) name:MPMovIEPlayerWillEnterFullscreenNotification object:nil];    [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(willExitFullscreen:) name:MPMovIEPlayerWillExitFullscreenNotification object:nil];    [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(enteredFullscreen:) name:MPMovIEPlayerDIDEnterFullscreenNotification object:nil];    [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(exitedFullscreen:) name:MPMovIEPlayerDIDExitFullscreenNotification object:nil];    [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(playbackFinished:) name:MPMovIEPlayerPlaybackDIDFinishNotification object:nil];    NSURL* movIEURL =  [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"tron" ofType:@"mov"]];    self.movIEController = [[MPMovIEPlayerController alloc] initWithContentURL:movIEURL];    self.movIEController.vIEw.frame = self.vIEw.frame;    [self.vIEw addSubvIEw:movIEController.vIEw];    [self.movIEController setFullscreen:YES animated:YES];    [self.movIEController play];}
总结

以上是内存溢出为你收集整理的iphone – 在iOS 3.2(iPad)中正确显示和关闭全屏MPMoviePlayerController全部内容,希望文章能够帮你解决iphone – 在iOS 3.2(iPad)中正确显示和关闭全屏MPMoviePlayerController所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1087183.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存