objective-c – 以编程方式显示MPMoviePlayerController中的控件

栏目: Objective-C · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/7256569/programmatically-show-controls-in-mpmovieplayercontroller

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

[self setControlStyle:MPMovieControlStyleEmbedded];

这不起作用.从本质上讲,在视频结尾我想控制显示.

如何以编程方式显示控件?

注意:控制器未处于全屏模式.

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

添加.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

}

翻译自:https://stackoverflow.com/questions/7256569/programmatically-show-controls-in-mpmovieplayercontroller


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

产品经理全栈运营实战笔记

产品经理全栈运营实战笔记

林俊宇 / 化学工业出版社 / 49.8元

本书凝结作者多年的产品运营经验,读者会看到很多创业公司做运营的经验,书中列举了几十个互联网产品的运营案例去解析如何真正做好一个产品的冷启动到发展期再到平稳期。本书主要分为六篇:互联网运营的全面貌;我的运营生涯;后产品时代的运营之道;揭秘刷屏事件的背后运营;技能学习;深度思考。本书有很多关于产品运营的基础知识,会帮助你做好、做透。而且将理论和作者自己的案例以及其他人的运营案例结合起来,会让读者更容易......一起来看看 《产品经理全栈运营实战笔记》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具