Hi
In order to make a seamlessly looping video using MediaPlayer (which annoyingly fades in and out of movies) I used the trick of setting the MP’s background to clearColor and loading a JPG of the first frame into the Main Window, so the movie then fades to transparent revealing the still and hopefully no-one’s the wiser.
Being a complete n00b I just wanted to check i was doing this the right way, because in the Simulator it runs fine, on the phone it runs fine once then each loop after that jumps to black before playing.

In my AppDelegate.m file I have


- (void)applicationDidFinishLaunching:(UIApplication *)application {

which loads the background image (I think!). The looping video is accomplished in MainView.m with:

UIView *mview= [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UIImageView *img=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"background.jpg"]];
img.frame=CGRectMake(0, 0, img.frame.size.width, img.frame.size.height);
[mview addSubview:img];
[img release];
[window addSubview:viewController.view];
[window addSubview:mview];
[window makeKeyAndVisible];
[window sendSubviewToBack:viewController.view];
[mview release];
}


-(void)awakeFromNib {

The movie plays and sends a notification when it’s finished so it’s played again.
Any advice on how to do this more efficiently and prevent black flashes between playbacks would be greatly appreciated!

NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"MyVid" ofType:@"m4v"];

NSURL *movieURL;

if (moviePath)
{
movieURL = [NSURL fileURLWithPath:moviePath];
}

if (movieURL != nil) {
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];

moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
moviePlayer.movieControlMode = MPMovieControlModeHidden;
moviePlayer.backgroundColor = [UIColor clearColor];

[moviePlayer play];
}

}

-(void)moviePlayBackDidFinish: (NSNotification*)notification
{
moviePlayer = [notification object];
[moviePlayer play];
}