Hey Everyone,
I ran into an issue with the iPhone (2.2.1) MediaPlayer that I haven't been able to resolve.
I created a simple ViewController project with a single press the play button to play the video.
The glitch is that if you press play and then immediately press "done" it takes you back to the button and the music will begin playing (if you wait a minute) and you press play to lock up the app.
It must have something to do with the "preloading" of the video.
Any thoughts on this one?
Phil
----
#import "VideoViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@implementation VideoViewController
@synthesize moviePlayer;
-(void)viewDidLoad {
if(!moviePlayer) {
//moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[self bundleURL]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[self movieURL]];
}
}
-(IBAction)playVideo {
[moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish

name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish

name:MPMoviePlayerContentPreloadDidFinishNotificat ion
object:nil];
}
-(void) moviePlayBackDidFinish

id)sender {
NSLog(@"playback stop");
[moviePlayer stop];
}
-(void) moviePreloadDidFinish

id)sender {
NSLog(@"preload");
}
- (NSURL *)movieURL {
return [NSURL URLWithString: @"http://code.agilephil.com/fox.m4v"];
//return [NSURL URLWithString: @"http://code.agilephil.com/video/iphone.m4v"];
}
- (NSURL *)bundleURL {
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"fox" ofType:@"m4v"];
return [NSURL fileURLWithPath:moviePath];
}
- (void)dealloc {
[moviePlayer release];
[super dealloc];
}
@end