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


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

查看所有标签

猜你喜欢:

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

Dojo权威指南

Dojo权威指南

拉塞尔 / 李松峰、李丽 / 机械工业出版社 / 2009-4 / 79.00元

通过使用Dojo这个工业强度的JavaScript工具箱,我们可以比使用其他任何Ajax框架更高效、更容易地创建JavaScript或Ajax驱动的应用程序和站点。 《Dojo权威指南》向读者展示了如何充分利用Dojo工具箱中包含的大量实用特性,以前所未有的效率开发出功能丰富、响应敏捷的Web应用程序。读者通过《Dojo权威指南》能够学习到创建复杂布局和表单控件(常见于高级桌面应用程序)的技......一起来看看 《Dojo权威指南》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具