如何知道电影播放器版本已完成?
我的目标是释放一个电影播放器(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有必要。
如果您只是释放播放器,然后调用 playButtonClicked,如下所示:
在第一行完成或电影释放之前,它不会执行第二行。这一切都在同一个线程上,因此它将按顺序执行。为此,您不需要计时器。尽管在您等待完成的内容在新线程上执行的情况下,您可以使用回调,而不是猜测需要多长时间(远小于 1 秒!)。
另外,为了避免误解,“完全释放”只是将retainCount减一。当它达到零时,它将自动释放。
顺便说一句,为什么在执行 playButtonClicked 之前释放(释放?) theMovie 很重要?
另外,您的 waitForReleaseFinish: 代码可以工作,但这是不必要的,因为 theMovie 将在创建计时器之前被释放。
There is no need.
If you just release the player and then call playButtonClicked, like this:
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.