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

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

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


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

查看所有标签

猜你喜欢:

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

Oricle8i Web开发指南

Oricle8i Web开发指南

(美)Bradley D.Brown / 机械工业出版社 / 2001-6 / 78.00元

本书用实际通用的策略,阐明了怎样一起来看看 《Oricle8i Web开发指南》 这本书的介绍吧!

html转js在线工具
html转js在线工具

html转js在线工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具