Question

I have an iPad app that has 4 buttons on the left side that corresponds to 4 different video clips. When a user taps the video they want to see, it appears on the right side. I am wanting it to appear to be loading (as if it were streaming over the internet). I added the UIActivityIndicator to the center of the black video frame and have a thread that pauses for 3 seconds. However, the player containing the previous video does not disappear. It just freezes on the last frame of the previous video for 3 seconds (hiding the activity indicator) and then the new video appears.

Any ideas on how to make the player temporarily be hidden? Thanks for any help. Here is my code:

-(IBAction) videoButton1{
   [player stop];
   [player release];

   [self.activityIndicator startAnimating];

   NSString *url = [[NSBundle mainBundle] pathForResource:@"video1" ofType:@"mov"];
   [self setupVideoPlayer:url];
}

-(void) setupVideoPlayer: (NSString *) url{
   player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url)];
   player.view.frame = CGRectMake(487, 205, 478, 320);

   [self.view addSubview:player.view];

   [NSThread sleepForTimeInterval:3.0];
   self.activityIndicator stopAnimating];

   [player play];
}
Was it helpful?

Solution

You can set the frame of your player to a View that you can make in IB or programmatically instead of doing a CGRectMake every time.

self.player.view.frame = self.viewForMovie.bounds;

self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

Then in your "videoButton1" you can set the alpha of the View to 0

viewForMovie.alpha = 0;

And in your "setupVideoPlayer" you can change the alpha back to 1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top