MPMoviePlayerController的使用(这个9.0之后已经废弃了,9.0之后的我会补充,这里只是想提一下)

时间:2019-09-17
本文章向大家介绍MPMoviePlayerController的使用(这个9.0之后已经废弃了,9.0之后的我会补充,这里只是想提一下),主要包括MPMoviePlayerController的使用(这个9.0之后已经废弃了,9.0之后的我会补充,这里只是想提一下)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

MPMoviePlayerController的使用:

RecordVideoplayView.h 文件:

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
NS_ASSUME_NONNULL_BEGIN

@interface RecordVideoplayView : UIView
/**
 不过这个9.0之后已经过时了
 */
@property (nonatomic ,strong)MPMoviePlayerController *Videoplayer;

@property (nonatomic ,strong) NSString *VideoplayUrl;//视频播放的地址


- (void)Videoplayshow ;//显示视频的view的方法 也可以添加到自己制定的容器上,不实现这个方法

- (void)VideoplayDias ;//视频不显示的方法


@end

NS_ASSUME_NONNULL_END

 RecordVideoplayView.m

#import "RecordVideoplayView.h"
#import <Masonry.h>
@implementation RecordVideoplayView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor =[UIColor blackColor];
        [self AddControls];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:_Videoplayer];

    }
    return self;
}


- (void)AddControls {
    [self addSubview:self.Videoplayer.view];
    [self.Videoplayer.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(self);
        make.top.mas_equalTo(self);
    } ];

}

- (void)setVideoplayUrl:(NSString *)VideoplayUrl {
    _VideoplayUrl =VideoplayUrl;
    self.Videoplayer.contentURL =[NSURL fileURLWithPath:_VideoplayUrl];
    [self.Videoplayer play];
}

- (MPMoviePlayerController *)Videoplayer {
    if (!_Videoplayer) {
        _Videoplayer =[[MPMoviePlayerController alloc]init];
        _Videoplayer.movieSourceType = MPMovieSourceTypeFile;// 播放本地视频时需要这句
        _Videoplayer.shouldAutoplay = YES;// 是否自动播放(默认为YES)
        _Videoplayer.controlStyle = MPMovieControlStyleFullscreen;//播放模式,全屏播放
    }
    return _Videoplayer;
    
}

-(void)myMovieFinishedCallback:(NSNotification*)notify {
    
    //释放的操作代码
    [self VideoplayDias];
    
}

- (void)Videoplayshow {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window addSubview:self];
}

- (void)VideoplayDias {
    [UIView animateWithDuration:0.3 animations:^{
        self.backgroundColor = [UIColor clearColor];
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}




@end

效果:

 再次提示,该类已经过时,只是学的时候给自己了解下而已

原文地址:https://www.cnblogs.com/hualuoshuijia/p/11532445.html