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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值