以编程方式显示 MPMoviePlayerController 中的控件

发布于 2024-12-02 07:14:51 字数 284 浏览 6 评论 0原文

我有一个 MPMoviePlayerController 子类,应该在播放完成时显示控件。我已将响应程序附加到 MPMoviePlayerPlaybackDidFinishNotification 通知,并尝试按如下方式设置控件样式:

[self setControlStyle:MPMovieControlStyleEmbedded];

这不起作用。本质上,在视频的末尾我想控制显示。 如何以编程方式显示控件?

注意:控制器不处于全屏模式。

I have a MPMoviePlayerController subclass that should show the controls when playback is finished. I have attached a responder to the MPMoviePlayerPlaybackDidFinishNotification notification and tried setting the control style as follows:

[self setControlStyle:MPMovieControlStyleEmbedded];

This is not working. In essence, at the end of the video I want to controls to show.
How can I show controls programatically?

NOTE: The controller is NOT in fullscreen mode.

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

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

发布评论

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

评论(1

一桥轻雨一伞开 2024-12-09 07:14:51

请找到我关于此的完整代码,它正在与我一起

添加 .h 类

@property(strong,nonatomic) MPMoviePlayerViewController * moviePlayer;

在 .m 类中添加此代码 添加此代码“传递电影 URl”

-(void) playMovie:(NSString *)filePath
{
    NSURL *theOutputURL = [NSURL fileURLWithPath:filePath];
    if(_moviePlayer)
        [_moviePlayer.moviePlayer setContentURL:theOutputURL];
    else
        _moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:theOutputURL];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(myMovieFinishedCallback:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:_moviePlayer.moviePlayer];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:_moviePlayer.moviePlayer];

    if (![_moviePlayer.moviePlayer isPreparedToPlay])
        [_moviePlayer.moviePlayer prepareToPlay];

    _moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [_moviePlayer.moviePlayer setFullscreen:YES];
    _moviePlayer.moviePlayer.controlStyle=MPMovieControlStyleEmbedded;
    [_moviePlayer.moviePlayer setContentURL:theOutputURL];
    _moviePlayer.view.frame = CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height);
    [_moviePlayer shouldAutorotateToInterfaceOrientation: AVCaptureVideoOrientationLandscapeRight];
    [self.view addSubview:_moviePlayer.view];
}


- (void) moviePlayerPlaybackStateDidChange: (NSNotification *) notification {
    if (_moviePlayer.moviePlayer.playbackState == MPMoviePlaybackStateStopped) {
        [_moviePlayer.moviePlayer setContentURL:[_moviePlayer.moviePlayer contentURL]];
        [_moviePlayer.moviePlayer play];
    }
}

-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
    //  to add your code after playback is finished

}

Kindly find my full Code about this , it's working with me

add .h class add this

@property(strong,nonatomic) MPMoviePlayerViewController * moviePlayer;

at .m class add this code "pass the movie URl"

-(void) playMovie:(NSString *)filePath
{
    NSURL *theOutputURL = [NSURL fileURLWithPath:filePath];
    if(_moviePlayer)
        [_moviePlayer.moviePlayer setContentURL:theOutputURL];
    else
        _moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:theOutputURL];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(myMovieFinishedCallback:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:_moviePlayer.moviePlayer];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:_moviePlayer.moviePlayer];

    if (![_moviePlayer.moviePlayer isPreparedToPlay])
        [_moviePlayer.moviePlayer prepareToPlay];

    _moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [_moviePlayer.moviePlayer setFullscreen:YES];
    _moviePlayer.moviePlayer.controlStyle=MPMovieControlStyleEmbedded;
    [_moviePlayer.moviePlayer setContentURL:theOutputURL];
    _moviePlayer.view.frame = CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height);
    [_moviePlayer shouldAutorotateToInterfaceOrientation: AVCaptureVideoOrientationLandscapeRight];
    [self.view addSubview:_moviePlayer.view];
}


- (void) moviePlayerPlaybackStateDidChange: (NSNotification *) notification {
    if (_moviePlayer.moviePlayer.playbackState == MPMoviePlaybackStateStopped) {
        [_moviePlayer.moviePlayer setContentURL:[_moviePlayer.moviePlayer contentURL]];
        [_moviePlayer.moviePlayer play];
    }
}

-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
    //  to add your code after playback is finished

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