iPhone:启动时播放视频不会退出

发布于 2024-12-11 14:39:18 字数 748 浏览 0 评论 0原文

我制作了一个在我的应用程序加载时播放的视频,但是即使您按下“完成”,它在播放后也不会退出。我做错了什么?

- (void)viewDidLoad {
NSBundle *bundle=[NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"Video Logo Final" ofType:@"mp4"];
NSURL *movieURL=[[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
theMovie.view.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
[self.view addSubview:theMovie.view];
[theMovie play];
[super viewDidLoad];  }

另外,我尝试将相同的代码放入“application didFinishLaunchingWithOptions”中,但在“[self.view addSubview:theMovie.view];”处收到警告 有什么想法吗?

ps 正如您可能猜到的那样,我对编程非常陌生,任何帮助将不胜感激......

i made a video playing when my app loads however it doen't quit after playing even if you prees "Done". What am i doing wrong?

- (void)viewDidLoad {
NSBundle *bundle=[NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"Video Logo Final" ofType:@"mp4"];
NSURL *movieURL=[[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
theMovie.view.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
[self.view addSubview:theMovie.view];
[theMovie play];
[super viewDidLoad];  }

Also, i made a try to put the same code in "application didFinishLaunchingWithOptions" but i get a warning at "[self.view addSubview:theMovie.view];"
Ay ideas about that?

p.s. As you probably guessed i am very new to programming, any help would be really appreciated...

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

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

发布评论

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

评论(1

疾风者 2024-12-18 14:39:18

基本上,您需要注册才能收到通知。

我这样做的方法是:

// Register for the playback finished notification
[[NSNotificationCenter defaultCenter] addObserver: self 
    selector: @selector(myMovieFinishedCallback:) 
    name: MPMoviePlayerPlaybackDidFinishNotification
    object: theMovie];

更改参数以适应您的应用程序。

这是 MPMoviePlayerPlaybackDidFinishNotification 的文档

另外,如果播放后没有“退出”(即使点击“完成”按钮),听起来您需要从最初添加到的视图中删除 theMovie MPMoviePlayerController 和关联的视图。

Basically you need to register for a notification.

The way I do it is:

// Register for the playback finished notification
[[NSNotificationCenter defaultCenter] addObserver: self 
    selector: @selector(myMovieFinishedCallback:) 
    name: MPMoviePlayerPlaybackDidFinishNotification
    object: theMovie];

Change the parameters to fit however it should in your app.

Here's the documentation for the MPMoviePlayerPlaybackDidFinishNotification.

Also, if it's not "quitting" after playing (even when hitting the "Done" button), it sounds like you need to remove the theMovie MPMoviePlayerController and associated view from the view you originally added it to.

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