// // JXXinRenLookDetialVc.m // shiku_im // // Created by 123 on 2020/5/29. // Copyright © 2020 Reese. All rights reserved. // #import "JXXinRenLookDetialVc.h" #import #import @interface JXXinRenLookDetialVc () @property (nonatomic,strong) AVPlayerViewController *AVPlayer; @property (nonatomic,weak) AVPlayerLayer *layer; @property (nonatomic,weak) UIButton *backBtn ; @end @implementation JXXinRenLookDetialVc - (void)click:(UIButton *)brn{ [g_navigation dismissViewController:self animated:YES]; } - (void)defineNavBaraaaa:(NSString *)title andRinghtBtnImg:(NSString *)image { UIView *navView = [[UIView alloc] init]; [self.view addSubview:navView]; navView.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH,JX_SCREEN_TOP); UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; backBtn.frame = CGRectMake(0,JX_SCREEN_HEIGHT>812?44:20,44, 44); [backBtn setImage:[UIImage imageNamed:@"photo_title_back_black"] forState:0]; backBtn.tag = 1001; [backBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside]; [navView addSubview:backBtn]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(80,(JX_SCREEN_HEIGHT>812?44:20), JX_SCREEN_WIDTH-160, 44)]; label.text = title; label.textColor = kRGBColor51; navView.backgroundColor = [UIColor whiteColor]; label.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular]; label.textAlignment = NSTextAlignmentCenter; [navView addSubview:label]; UIButton *backBtnaaa = [[UIButton alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH-60, JX_STATUSBAR_H, 44, 44)]; [backBtnaaa setTitle:@"x" forState:UIControlStateNormal]; [backBtnaaa setTitleColor:kRGBColor51 forState:UIControlStateNormal]; //backBtnaaa.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.3]; //backBtnaaa.layer.cornerRadius=22; //backBtnaaa.layer.masksToBounds=YES; [backBtnaaa addTarget:self action:@selector(addtBtnClick) forControlEvents:UIControlEventTouchUpInside]; [navView addSubview:backBtnaaa]; } - (id)init { self = [super init]; if (self) { [self defineNavBaraaaa:@"新人必看" andRinghtBtnImg:@""]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.navigationItem.title=@"新人必看"; UIImageView *iconIMG=[[UIImageView alloc]init]; iconIMG.userInteractionEnabled=YES; iconIMG.image=[UIImage imageNamed:@"wanzhuanjixin"]; [self.view addSubview:iconIMG]; [iconIMG mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.mas_equalTo(JX_SCREEN_TOP); make.bottom.mas_equalTo(0); make.right.mas_equalTo(0); }]; UIButton *touchBtn=[[UIButton alloc]init]; touchBtn.backgroundColor=[UIColor clearColor]; [iconIMG addSubview:touchBtn]; [touchBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(iconIMG.mas_centerX); make.bottom.mas_equalTo(-60); make.width.mas_equalTo(110); make.height.mas_equalTo(110); }]; [touchBtn addTarget:self action:@selector(playBtn) forControlEvents:UIControlEventTouchUpInside]; } /** * 背景视频 */ -(void)playBtn{ //初始化AVPlayer self.AVPlayer = [[AVPlayerViewController alloc]init]; //多分屏功能取消 self.AVPlayer.allowsPictureInPicturePlayback = NO; //设置是否显示媒体播放组件 self.AVPlayer.showsPlaybackControls = false; NSString *strUl=@"http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4"; //[[NSBundle mainBundle] pathForResource:@"movie" ofType:@".mp4"]; //初始化一个播放单位。给AVplayer 使用 AVPlayerItem *item = [[AVPlayerItem alloc]initWithURL:[NSURL URLWithString :strUl]]; AVPlayer *player = [AVPlayer playerWithPlayerItem:item]; //layer AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:player]; [layer setFrame:CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-JX_SCREEN_TOP)]; //设置填充模式 layer.videoGravity = AVLayerVideoGravityResizeAspect; self.layer=layer; //设置AVPlayerViewController内部的AVPlayer为刚创建的AVPlayer self.AVPlayer.player = player; //添加到self.view上面去 [self.view.layer addSublayer:layer]; //开始播放 [self.AVPlayer.player play]; //这里设置的是重复播放。 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playDidEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:item]; //定时器。延迟3秒再出现进入应用按钮 [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(prepareForbackIMG) userInfo:nil repeats:YES]; } - (void)addtBtnClick{ [self.AVPlayer.player pause]; [self.backBtn removeFromSuperview]; [self.layer removeFromSuperlayer]; [self.backBtn removeFromSuperview]; self.layer = nil; self.AVPlayer=nil; self.AVPlayer.player=nil; self.backBtn.hidden=YES; } - (void)prepareForbackIMG{ self.backBtn.hidden=NO; } //播放完成的代理 - (void)playDidEnd:(NSNotification *)Notification{ //播放完成后。设置播放进度为0 。 重新播放 // [self.layer removeFromSuperlayer]; // self.layer = nil; [self.AVPlayer.player seekToTime:CMTimeMake(0, 1)]; //开始播放 [self.AVPlayer.player play]; } @end