• OC 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
    

    效果:

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

  • 相关阅读:
    oracle 认证方式
    Oracle
    深入理解Java的接口和抽象类
    mongoDB的学习【小白的福音】
    对于vertical-align的学习
    flex的学习 flexBox的学习
    用伪类添加翘边阴影::before和::after
    icon小图标
    url 中的 ? 和 & 还有 # 的作用
    解决img的1px空白问题
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/11532445.html
Copyright © 2020-2023  润新知