网上有,拿来改改。挺好用的。比较简单。分享。
- (void) Playback : (id) sender
{
//指定播放的名字和地址
NSString *path = [[NSBundle mainBundle] pathForResource:@"ss" ofType:@"mov"];
// m4a格式也是允许的。
MPMoviePlayerController* theMovie=[[[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]] retain];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
[theMovie play];
}
- (void) setUpForPlay: (NSNotification *) notification
{
UIButton *button = (UIButton *)[self.view viewWithTag:BUTTON_TAG];
// Prepare button for re-starting
[button setTitle:@"Start" forState:UIControlStateNormal];
[button removeTarget:self action:@selector(stopPlayback:) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(startPlayback:) forControlEvents: UIControlEventTouchUpInside];
}