异步加载的MPMoviePlayerController没有时间价值 [英] Asynchronous MPMoviePlayerController load has no duration value
问题描述
我假设 initWithContentURL:
方法不是异步的。我添加下面的方法做负载在后台,然后分配临时球员我的变量。
I assume that the initWithContentURL:
method is not asynchronous. I added the following methods to do the load in the background and then assign the temporary player to my variable.
-(void)createPlayer {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MPMoviePlayerController *temp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"URLString"]];
[self performSelectorOnMainThread:@selector(passPlayer:) withObject:temp waitUntilDone:YES];
[temp release];
[pool release];
}
-(void)passPlayer:(MPMoviePlayerController*)temp {
player = [temp retain];
player.movieSourceType = MPMovieSourceTypeStreaming;
//player.view.hidden = YES;
//[self.view addSubview:player.view];
[player prepareToPlay];
}
问题是,当我打印出来的球员,我得到这个持续时间:
The problem is when I print out the duration of the player I get this:
double duration = player.duration;
NSLog(@"duration: %f, duration);
console output: duration: nan
我已经添加了 MPMoviePlayerControllerNotifications
当有可用的持续时间值被通知,但即使如此,该值仍然是'南'。如果我做了主线程的负载持续时间有一个值,但我不希望使用主线程,所以我的用户界面不会锁定。
I have added the MPMoviePlayerControllerNotifications
to be notified when there is a duration value available, but even then the value is still 'nan'. If I do the load on the main thread the duration has a value, but I don't want to use the main thread so my UI doesn't lock up.
任何想法?
推荐答案
从官方文档:
讨论
如果电影的持续时间是未知的,在该属性的值是0.0。如果持续时间随后确定,这个属性被更新和MPMovieDurationAvailableNotification通知发布。
Discussion If the duration of the movie is not known, the value in this property is 0.0. If the duration is subsequently determined, this property is updated and a MPMovieDurationAvailableNotification notification is posted.
因此,使用NSNotificationCenter注册MPMovieDurationAvailableNotification通知。
So use NSNotificationCenter to register the MPMovieDurationAvailableNotification notification.
这篇关于异步加载的MPMoviePlayerController没有时间价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!