【问题标题】:MPMoviePlayerController - Video stops when I change contentURLMPMoviePlayerController - 当我更改 contentURL 时视频停止
【发布时间】:2012-03-05 11:30:59
【问题描述】:

在播放电影时,如果我更改 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
  • 你想达到什么目的?
  • 客户需要额外的控件在视频列表之间移动。始终是客户的请求!

标签: iphone xcode cocoa-touch mpmovieplayercontroller mpmovieplayer


【解决方案1】:

提供新的contentURL 后,播放器停止播放是完全正常的。

MPMoviePlayerController.view 但是通常不会被自动删除。我假设您忘记了您的通知处理程序之一为您做类似的事情。

【讨论】:

  • 谢谢,我会调查的。查看 Apple 的文档,似乎我需要做的就是更新内容 URL:如果您在播放电影时设置此属性,则该电影会暂停并开始加载新电影。新电影从头开始播放。
猜你喜欢
  • 1970-01-01
  • 2011-05-29
  • 2017-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多