I assume the method is initWithContentURL:not asynchronous. I added the following methods to do the loading in the background and then assign a 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 prepareToPlay];
}
The problem is when I print the playback time of the player, I get the following:
double duration = player.duration;
NSLog(@"duration: %f, duration);
console output: duration: nan
I added MPMoviePlayerControllerNotificationsfor notification when a duration value is available, but even then the value is still “nan”. If I load the main thread, the duration matters, but I do not want to use the main thread, so my user interface is not blocked.
Any ideas?
source
share