播放视频后更改视图

发布于 2024-12-11 17:08:32 字数 1921 浏览 0 评论 0原文

当我单击播放按钮时,我的视频可以工作,并且我知道视图更改的代码可以工作。我的视频播放完毕后,我似乎无法改变视图,不知道出了什么问题。视频播放完毕后,有什么想法可以改变视图吗?

我播放电影的代码

-(IBAction)playMovie:(id)sender {
NSString *movieUrl = [[NSBundle mainBundle] pathForResource:@"Movie_1666" ofType:@"m4v"]; 
playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:movieUrl]];
//Smoothe Transition
//[self presentMoviePlayerViewControllerAnimated:playerController];
//Instant Transistion
[self presentModalViewController:playerController animated:NO];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
[playerController.moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerController]; }

我更改视图的方法

- (void)playbackFinished:(NSNotification*) notification {
MPMoviePlayerController *playerController = [notification object];
[[NSNotificationCenter defaultCenter] 
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:playerController];

View2 *view2 = [[View2 alloc] initWithNibName:@"View2" bundle:nil];
View2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:view2 animated:YES]; }

编辑: 我的Notification对象错误并且没有触发我的playbackFinished方法 这个改变解决了这个问题。

- (void)playbackFinished:(NSNotification*) notification {
playerController = [notification object];
[[NSNotificationCenter defaultCenter] 
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:playerController];

我还将其放入我的头文件中,使其成为全局的,以便在我的playbackFinished方法中使用

MPMoviePlayerViewController *playerController;

My Video works when I click my play button, and I know the code for my view change works. I just can't seem to get the view to change after my video is done playing, not sure what is going wrong. Any ideas to get the view to change once the video is done playing?

My code to play movie

-(IBAction)playMovie:(id)sender {
NSString *movieUrl = [[NSBundle mainBundle] pathForResource:@"Movie_1666" ofType:@"m4v"]; 
playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:movieUrl]];
//Smoothe Transition
//[self presentMoviePlayerViewControllerAnimated:playerController];
//Instant Transistion
[self presentModalViewController:playerController animated:NO];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
[playerController.moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerController]; }

My method to change views

- (void)playbackFinished:(NSNotification*) notification {
MPMoviePlayerController *playerController = [notification object];
[[NSNotificationCenter defaultCenter] 
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:playerController];

View2 *view2 = [[View2 alloc] initWithNibName:@"View2" bundle:nil];
View2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:view2 animated:YES]; }

EDIT:
My Notification object was wrong and wasn't triggering my playbackFinished method
this change fixes that.

- (void)playbackFinished:(NSNotification*) notification {
playerController = [notification object];
[[NSNotificationCenter defaultCenter] 
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:playerController];

I also put this in my header file to make it global for use in my playbackFinished method

MPMoviePlayerViewController *playerController;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠北森屋 2024-12-18 17:08:32

电影播放完毕后,关闭 playerController 视图(不带动画)。另请检查您是否在主线程中呈现 View2

编辑:
通过以下方式关闭 playerController

[playerController dismissModalViewControllerAnimated:NO];

Once the movie play finished, dismiss the playerController view without animation. Also check, whether you are presenting the View2 in main thread.

Edit:
Dismiss the playerController by

[playerController dismissModalViewControllerAnimated:NO];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文