iPhone SDK:停止视频

发布于 2024-10-19 00:08:35 字数 688 浏览 2 评论 0原文

如何在离开视图后停止视频并在再次返回原始视图时再次播放视频?

以下是在原始视图中播放视频的代码:

- (void)viewDidLoad {
    NSBundle *bundle=[NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"Video" ofType:@"mp4"];
    NSURL *movieURL=[[NSURL fileURLWithPath:moviePath] retain];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    theMovie.view.frame = CGRectMake(104.0, 134.0, 200.0, 250.0);
    [self.view addSubview:theMovie.view];
    [theMovie play];

    [super viewDidLoad];
    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];      
}

How can I stop a video once I navigate away from a view and make the video play again when I get back to the original view again?

Here is the code to play the video in the original view:

- (void)viewDidLoad {
    NSBundle *bundle=[NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"Video" ofType:@"mp4"];
    NSURL *movieURL=[[NSURL fileURLWithPath:moviePath] retain];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    theMovie.view.frame = CGRectMake(104.0, 134.0, 200.0, 250.0);
    [self.view addSubview:theMovie.view];
    [theMovie play];

    [super viewDidLoad];
    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];      
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2024-10-26 00:08:35
  1. theMovie 实例 var
  2. -(void) viewWillDisappear:(BOOL)animated 中停止播放

,当您导航回此视图时,它应该开始播放。或者将此代码移至 -(void) viewDidAppear:(BOOL)animated

  1. Make theMovie instance var
  2. Stop playing in the -(void) viewWillDisappear:(BOOL)animated

And it should start playing when you navigate back to this view. Or move this code to -(void) viewDidAppear:(BOOL)animated

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文