0

在影片播放過程中,如果我改變我的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];} 

感謝您的幫助。

+0

你爲什麼想改變'contentURL'邊玩? – Raptor 2012-03-05 11:33:43

+0

你試圖達到什麼目的? – Till 2012-03-05 22:31:23

+0

客戶希望額外控制在視頻列表之間移動。始終是客戶的要求! – user707666 2012-03-06 00:44:23

回答

1

這是完全正常的玩家停止玩一次新的contentURL供應。

MPMoviePlayerController.view但是通常不被自動刪除。我假設你忘記了你的一個通知處理程序爲你做了這樣的事情。

+0

謝謝,我會研究一下。縱觀蘋果的文檔,好像所有我需要做的是更新內容網址: 如果您在電影播放期間設置該屬性,那部電影,並暫停新的電影開始加載。新電影開始播放。 – user707666 2012-03-06 00:46:21

+0

@ user707666,這是完全正確的。 – Till 2012-03-07 22:20:34