I have a piece of code that works on the iPhone. I load a UIImageView, make it invisible with an alpah = 0, and then play a video over it using AVPlayerLayer. When the video is done I remove the playerLayer (in a Notification) and change my alpha of myImage to 1.
Two different things happen when I use an iPad.
First, the alpha property does not do anything. The UIImage is visible.
Second, setting the playerLayer frame to the size of the myImage from only works when I use
[playerLayer setFrame:CGRectMake(0, 0, width, height)];
instead of just using
playerLayer.frame = myImage.frame
Here is the code. Thanks for anyone that can clear this up for me.
-(void)playMovie2: (NSString *) fileName
{
#define degreesToRadian(x) (M_PI*(x)/180.0)
CGFloat height, width;
NSLog(@"in playMovie2 simulation!");
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: fileName ofType:@"mov"]];
AVPlayer *player = [AVPlayer playerWithURL:url];
playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
//cgrectmake: xfloat, yfloat, width, height
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
height = self.view.frame.size.height;
width = self.view.frame.size.width;
[myImage setFrame:CGRectMake(0, 0, width, height)];
NSLog(@"iPhone %f %f",width, height);
}
else{
//we need this because I only used one XIB file for the iPhone and iPad
//we need to get the dimension from the device
height = [UIScreen mainScreen].currentMode.size.height;
width = [UIScreen mainScreen].currentMode.size.width;
height = (height/2);
width = (width/2);
[myImage setFrame:CGRectMake(0, 0, width, height)];
NSLog(@"iPad %f %f",width, height);
}
self.myImage.alpha = 0;
//[playerLayer setFrame:CGRectMake(0, 0, width, height)]; // For some reason I need to use this
playerLayer.frame = myImage.frame; //instead of this for iPad
[self.view.layer addSublayer:playerLayer];
[player play];
}