Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
I have an AVPlayer in an app I'm building that absolutely mustn't start playing until after a UIImage is shown. I'm finding, though, that it sometimes starts playing before the image. I created another project just to see what would happen if I broke after setImage, and the result was quite surprising: the image did not get set until after I continued past the breakpoint. Here's my code:

Code:
- (void)viewDidAppear:(BOOL)animated

{

    [superviewDidAppear:animated];

    NSString *fileName = @"nottelling";

    UIImage *image = [UIImageimageNamed:fileName];

    [self.imageViewsetImage:image];

    NSLog(@"image: %@",image);

}

Will someone please help? Thanks.

The Solution That Solved My Problem

I checked the sizes (in pixels) of the images, and they were way too big. Bigger size = greater processor load. Therefore, using an image manipulation program, I reduced the sizes.
 
Last edited:
The code is incomplete, it doesn't show the actual AVPlayer, but I assume you are loading, setting the image then an AVPlayer.

I would start by finding if they are on different threads. Maybe even set the AVPlayer as part of a completion block or seek confirmation of the image being shown before the AVPlayer is started.

You can also examine the resources used to start the AVPlayer (file loading, buffering, display settings,...) Then see if there is some kind of "ReadToPlay" call or block.
 
You should probably try to show the image earlier, in viewDidLoad or viewWillAppear. Or build the image in viewDidLoad but assign it later. I would expect that an image loaded by UIImage.imageNamed would load instantly. imageNamed goes through the application imageCache and UIImage has the ability to be purged and reloaded from/to memory in response to memory warnings. I don't believe there's any way to tell if the image is loaded or visible though.
 
You should probably try to show the image earlier, in viewDidLoad or viewWillAppear. Or build the image in viewDidLoad but assign it later. I would expect that an image loaded by UIImage.imageNamed would load instantly. imageNamed goes through the application imageCache and UIImage has the ability to be purged and reloaded from/to memory in response to memory warnings. I don't believe there's any way to tell if the image is loaded or visible though.
I found the solution. Check the image res, and make sure it's appropriate for the rendering device. Images are drawn in a run loop.
 
imageNamed only loads images from the app bundle so you should know at compile time if you have the right resolutions. I guess the problem was that the resolution was too high?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.