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

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

内容简介:翻译自: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


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

查看所有标签

猜你喜欢:

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

领域特定语言

领域特定语言

Martin Fowler / ThoughtWorks中国 / 机械工业出版社华章公司 / 2013-3 / 89.00元

本书是DSL领域的丰碑之作,由世界级软件开发大师和软件开发“教父”Martin Fowler历时多年写作而成,ThoughtWorks中国翻译。全面详尽地讲解了各种DSL及其构造方式,揭示了与编程语言无关的通用原则和模式,阐释了如何通过DSL有效提高开发人员的生产力以及增进与领域专家的有效沟通,能为开发人员选择和使用DSL提供有效的决策依据和指导方法。 全书共57章,分为六个部分:第一部分介......一起来看看 《领域特定语言》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具