退出 MPMediaPlayerController 视图

发布于 2024-12-11 05:59:11 字数 1317 浏览 0 评论 0原文

我正在编写一个简单的方法来全屏启动流媒体视频并让用户停止按“完成”按钮。问题是,我无法删除 MPMediaPlayerController 视图,或者可能我的操作方式错误。

- (IBAction)playVideoButtonPressed:(id)sender {
    NSURL *url = [NSURL URLWithString:@"http://mysite.com/video.mov"];
    mp = [[MPMoviePlayerController alloc] initWithContentURL: url];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerPlaybackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];

    if ([mp respondsToSelector:@selector(setFullscreen:animated:)]) {  
        mp.controlStyle = MPMovieControlStyleFullscreen;  
        mp.shouldAutoplay = YES;
        [self.view addSubview:mp.view];  
        [mp.view setTag:3];
        [mp setFullscreen:YES animated:YES];  
    }
    [[NSNotificationCenter defaultCenter] addObserver:self            
        selector:@selector(moviePlayBackDidFinish:) 
        name:MPMoviePlayerPlaybackDidFinishNotification
        object:mp];

    [mp play];
}

- (void)moviePlayBackDidFinish:(id)sender {
      NSLog(@"Quitting MoviePlayer");
      [mp.view removeFromSuperview];    
}

这个想法是,通过单击应用程序中的按钮来调用 MPMediaPlayerController 视图,并通过单击“完成”视频或视频结束时将其关闭。

I am writing a simple method to start a streaming video full-screen and letting the user quit pressing the "Done" button. Problem is, I can't remove the MPMediaPlayerController view, or perhaps I am doing it the wrong way.

- (IBAction)playVideoButtonPressed:(id)sender {
    NSURL *url = [NSURL URLWithString:@"http://mysite.com/video.mov"];
    mp = [[MPMoviePlayerController alloc] initWithContentURL: url];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerPlaybackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];

    if ([mp respondsToSelector:@selector(setFullscreen:animated:)]) {  
        mp.controlStyle = MPMovieControlStyleFullscreen;  
        mp.shouldAutoplay = YES;
        [self.view addSubview:mp.view];  
        [mp.view setTag:3];
        [mp setFullscreen:YES animated:YES];  
    }
    [[NSNotificationCenter defaultCenter] addObserver:self            
        selector:@selector(moviePlayBackDidFinish:) 
        name:MPMoviePlayerPlaybackDidFinishNotification
        object:mp];

    [mp play];
}

- (void)moviePlayBackDidFinish:(id)sender {
      NSLog(@"Quitting MoviePlayer");
      [mp.view removeFromSuperview];    
}

The idea is that the MPMediaPlayerController view is called clicking on a button in the app, and it is dismissed by clicking the "Done" video or when the video ends.

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

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

发布评论

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

评论(1

北座城市 2024-12-18 05:59:11

我应该使用 MPMoviePlayerViewController。

I should have used MPMoviePlayerViewController.

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