MPMoviePlayerController - видео останавливается, когда я меняю contentURL - PullRequest
0 голосов
/ 05 марта 2012

Во время воспроизведения фильма, если я изменяю свой контентURL, фильм перестает воспроизводиться, и просмотр удаляется.

Я пробовал решение здесь , но оно все равно не работает.

Вот мой код для воспроизведения фильма:

- (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];}

Спасибо за любую помощь.

1 Ответ

1 голос
/ 06 марта 2012

Игрок может полностью прекратить играть, как только появится новый contentURL.

Однако MPMoviePlayerController.view обычно не удаляется автоматически. Я предполагаю, что вы забыли, что один из ваших обработчиков уведомлений делает что-то подобное для вас.

...