Asynchronous MPMoviePlayerController load does not matter duration

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.view.hidden = YES;
//[self.view addSubview:player.view];
[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?

+3
source share
3

:

, 0.0. , MPMovieDurationAvailableNotification.

NSNotificationCenter MPMovieDurationAvailableNotification.

+2

, . , . , , NAN .

-, initWithContentURL:, , , , . , , , , , , , .

+4

, . MPMovieDurationAvailableNotification, , .

MPMovieDurationAvailableNotification

This notice is published when the duration of the movie object is determined. The notification object is an MPMoviePlayerController Object. There is no user information dictionary. the duration value is reflected in the duration property of the movie controller.

Source: Apple Documentation

+3
source

All Articles