【发布时间】:2011-06-18 18:06:04
【问题描述】:
我假设initWithContentURL: 方法不是异步的。我添加了以下方法在后台进行加载,然后将临时播放器分配给我的变量。
-(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];
}
问题是当我打印出播放器的持续时间时,我得到了这个:
double duration = player.duration;
NSLog(@"duration: %f, duration);
console output: duration: nan
我添加了MPMoviePlayerControllerNotifications,以便在有可用的持续时间值时收到通知,但即便如此,该值仍然是“nan”。如果我在主线程上加载,则持续时间有一个值,但我不想使用主线程,所以我的 UI 不会锁定。
有什么想法吗?
【问题讨论】:
-
您最初的假设是错误的 - initWithContentURL 是异步的。
-
@Till 有什么文档可以指点我吗?
-
不,不幸的是,我得到的只是丰富的使用经验。即使远程服务器无法/几乎无法访问,它也不会引入可识别的延迟。
-
@Till 看起来你是对的。导致推送延迟的行是
prepareToPlay。但是,如果我删除那条线,玩家根本不会玩。我尝试设置一个计时器以在视图加载后一秒钟调用它,但它根本不会播放。有什么想法吗? -
好吧,明确地说,MPMoviePlayerController 方法都没有使用同步网络访问。如果使用得当,它们都会立即返回。我建议您删除所有手动穿线并再次检查。 prepareToPlay 在我已经完成的播放器实现中也会立即返回。
标签: iphone ios4 asynchronous mpmovieplayercontroller