在影片播放過程中,如果我改變我的contentURL電影停止播放和視圖被刪除。的MPMoviePlayerController - 視頻停止時,我改變的contentURL
我試圖解決here,但它仍然無法正常工作。
這裏是我的代碼來播放影片:
- (void) playMovie:(NSURL *)moviePath{
theMovie = [[MPMoviePlayerController alloc] initWithContentURL: moviePath];
UIView * movieView = [theMovie view];
[movieView setFrame: CGRectMake(0, 0, 480, 320)];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
CGAffineTransform landscapeTransform;
landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80);
[movieView setTransform: landscapeTransform];
self.theMovie.scalingMode = MPMovieScalingModeAspectFit;
self.theMovie.fullscreen = TRUE;
self.theMovie.controlStyle = MPMovieControlStyleNone;
[self performSelector:@selector(showCtrlsOnTouch) withObject:NULL afterDelay:0.1];
[self.theMovie prepareToPlay];
int a = currentMovie;
int b = [self.tableDataSource count] - 1;
if(a < b)
{
UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
nextButton.frame = CGRectMake(360.0, 138.0, 100.0, 44.0);
[nextButton setTitle:@"Next" forState:UIControlStateNormal];
[self.theMovie.view addSubview:nextButton];
[nextButton addTarget:self action:@selector(playNextMovie:) forControlEvents:UIControlEventTouchUpInside];
}
if(currentMovie > 0)
{
UIButton *previousButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
previousButton.frame = CGRectMake(40.0, 138.0, 100.0, 44.0);
[previousButton setTitle:@"Prev" forState:UIControlStateNormal];
[self.theMovie.view addSubview:previousButton];
[previousButton addTarget:self action:@selector(playPreviousMovie:) forControlEvents:UIControlEventTouchUpInside];
}
[[[UIApplication sharedApplication] keyWindow] addSubview: movieView];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(movieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: self.theMovie];}
這裏是我的代碼來切換電影:
- (void) playNextMovie:(id) sender{
currentMovie++;
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:currentMovie];
NSString *videoString = [NSString stringWithFormat:@"%@", [dictionary objectForKey:@"videoFile"]];
NSString *videoPath = [[NSBundle mainBundle] pathForResource:videoString ofType:@"m4v"];
NSLog(@"Video Path: %@", videoPath);
NSURL *moviePath = [NSURL fileURLWithPath: videoPath];
self.theMovie.contentURL = moviePath;
[self.theMovie prepareToPlay];}
感謝您的幫助。
你爲什麼想改變'contentURL'邊玩? – Raptor 2012-03-05 11:33:43
你試圖達到什麼目的? – Till 2012-03-05 22:31:23
客戶希望額外控制在視頻列表之間移動。始終是客戶的要求! – user707666 2012-03-06 00:44:23