如何知道电影播放器​​版本已完成?

发布于 2024-09-04 11:51:16 字数 1104 浏览 2 评论 0原文

我的目标是释放一个电影播放器​​(theMovie),然后在完全释放后启动另一个动作(所谓的 playButtonClicked)。我使用 PerformSelector 将“playButtonClicked”延迟 1 秒,效果很好。代码是:

[电影发行]; [self PerformSelector:@selector(playButtonClicked) withObject:nil afterDelay:1];

然而,我不想总是拖延1秒。我想在“theMovie”完全发布后立即启动“playButtonClicked”。我尝试了以下代码,但它不起作用,因为 [timer userInfo] 永远不会为零。 有谁知道如何检查电影播放器​​版本是否已完成。

[theMovie release];
//[self performSelector:@selector(playButtonClicked) withObject:nil afterDelay:1];

NSTimer *atimer =   [NSTimer scheduledTimerWithTimeInterval:0.1 target:self 
                                                  selector:@selector(waitForReleaseFinish:)
                                                  userInfo: (MPMoviePlayerController*) theMovie repeats:YES];

waitForRleaseFinish: (NSTimer *)timer 的代码是:

if ([timer userInfo]==nil)  //here I actually want to test if (theMovie==nil),but I don't know how to do and I'm not sure if it is a correct way to determine the release finished.
{
     [timer invalidate];
    [self playButtonClicked];
}

期待帮助。谢谢。

I aims to release a movieplayer (theMovie) and then start another action (so-called playButtonClicked) after it is completely released. I used performSelector to delay the "playButtonClicked" for 1 second and it works well. The code is:

[theMovie release];
[self performSelector:@selector(playButtonClicked) withObject:nil afterDelay:1];

However, I don't want to always delay 1 second. I want to start the "playButtonClicked" as soon as "theMovie" is completely released. I tried the following code, but it didn't work because [timer userInfo] never is nil.
Does anybody know how to check a movieplayer release finished.

[theMovie release];
//[self performSelector:@selector(playButtonClicked) withObject:nil afterDelay:1];

NSTimer *atimer =   [NSTimer scheduledTimerWithTimeInterval:0.1 target:self 
                                                  selector:@selector(waitForReleaseFinish:)
                                                  userInfo: (MPMoviePlayerController*) theMovie repeats:YES];

The code of waitForRleaseFinish: (NSTimer *)timer is:

if ([timer userInfo]==nil)  //here I actually want to test if (theMovie==nil),but I don't know how to do and I'm not sure if it is a correct way to determine the release finished.
{
     [timer invalidate];
    [self playButtonClicked];
}

Look forward to helps. Thank you.

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

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

发布评论

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

评论(1

静若繁花 2024-09-11 11:51:16

没有必要。

如果您只是释放播放器,然后调用 playButtonClicked,如下所示:

[theMovie release];
[self playButtonClicked];

在第一行完成或电影释放之前,它不会执行第二行。这一切都在同一个线程上,因此它将按顺序执行。为此,您不需要计时器。尽管在您等待完成的内容在新线程上执行的情况下,您可以使用回调,而不是猜测需要多长时间(远小于 1 秒!)。

另外,为了避免误解,“完全释放”只是将retainCount减一。当它达到零时,它将自动释放。

顺便说一句,为什么在执行 playButtonClicked 之前释放(释放?) theMovie 很重要?

另外,您的 waitForReleaseFinish: 代码可以工作,但这是不必要的,因为 theMovie 将在创建计时器之前被释放。

There is no need.

If you just release the player and then call playButtonClicked, like this:

[theMovie release];
[self playButtonClicked];

It won't execute the second line until the first is completed, or until theMovie is released. This is all on the same thread so it will execute in order. You don't need a timer for this. Although in situations where what you're waiting for to finish executes on a new thread, you would use a callback, rather than guessing how long it takes (which is much less than 1 second!).

Also, just so you don't misunderstand, "completely releasing" is just subtracting the retainCount by one. It will automatically deallocate when it reaches zero.

Just as a side note, why is it important that theMovie is released (deallocated?) before playButtonClicked is executed?

Also, your waitForReleaseFinish: code would work, but it's unnecessary because theMovie would be released before the timer is created.

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