123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- //
- // LeeVideoVC.m
- // jiaPei
- //
- // Created by EchoShacolee on 2018/3/8.
- // Copyright © 2018年 JCZ. All rights reserved.
- //
- #import "LeeVideoVC.h"
- #import "AGPlayerView.h"
- #import <RealReachability/RealReachability.h>
- @interface LeeVideoVC ()
- {
- BOOL isGoOn4G;
- NSString *urlStr;
- }
- @property (strong, nonatomic) AGPlayerView *playerView;
- @end
- @implementation LeeVideoVC
- -(void)dealloc{
- [GLobalRealReachability stopNotifier];
- [[NSNotificationCenter defaultCenter]removeObserver:self name:kRealReachabilityChangedNotification object:nil];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"videoFinish%@%@",_dataDic[@"id"],[self getVideoFormat]]];
- if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
- //本地视频
- NSString *videoPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"video%@%@",_dataDic[@"id"],[self getVideoFormat]]];
- urlStr = videoPath;
- NSURL *url = [NSURL fileURLWithPath:urlStr isDirectory:NO];
- [self.playerView updatePlayerWithURL:url];
- }else{
-
- //网络监测
- [GLobalRealReachability startNotifier];
- ReachabilityStatus status = [GLobalRealReachability currentReachabilityStatus];
- if (status == RealStatusNotReachable) {
- ShowMsg(@"当前无网络连接");
- } else if (status == RealStatusViaWWAN){
- // ShowMsg(@"你正在使用的是运营商网络,继续观看可能会产生超额流量费用");
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"该视频还未下载,在线播放会产生大量流量,建议在WiFi环境下下载至本地后播放" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"下载视频",@"继续播放", nil];
- alert.tag = 1;
- [alert show];
- }else{
- //真Wi-Fi 播放吧 //未知 不知道是有网还是没网 索性播放了吧
- urlStr = _dataDic[@"videoPath"];
- NSURL *url = [NSURL URLWithString:urlStr];
- [self.playerView updatePlayerWithURL:url];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(networkChanged:)
- name:kRealReachabilityChangedNotification
- object:nil];
- }
- }
-
- [self myInit];
-
- }
- -(AGPlayerView *)playerView{
- if (!_playerView) {
- CGFloat zz = 0;
- if (is_iPhoneX) {
- zz = kStatusHeight;
- }
- _playerView = [[AGPlayerView alloc]initWithFrame:CGRectMake(0, zz, kSize.width, kSize.width*14/25)];
- [self.view addSubview:_playerView];
- }
- return _playerView;
- }
- -(void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- if (self.playerView.isPlaying) {
- [self.playerView pause];
- }
- [self.playerView removeObserveAndNOtification];
- [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
- [[UIApplication sharedApplication] setStatusBarStyle:(UIStatusBarStyleDefault)];
- }
- -(void)myInit{
- self.view.backgroundColor = [UIColor blackColor];
- self.playerView.titleLabel.text = _dataDic[@"title"];
- __weak typeof(self)weakSelf = self;
- self.playerView.goBackBlock = ^{
- if (weakSelf.playerView.isLandscape) {
- weakSelf.playerView.isLandscape = NO;
- return;
- }
- if (weakSelf.playerView.isPlaying) {
- [weakSelf.playerView pause];
- }
-
- [weakSelf dismissViewControllerAnimated:YES completion:nil];
- };
-
-
- CGFloat y = CGRectGetMaxY(self.playerView.frame);
- CGFloat h = kSize.height - y;
- UIView* titleBar = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, h)];
- titleBar.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:titleBar];
- [self.view bringSubviewToFront:self.playerView];
-
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 15, kSize.width, 20)];
- [label setText:@"内容详解" Font:FontTitle TextColor:titleColor Alignment:NSTextAlignmentLeft];
- [titleBar addSubview:label];
-
- UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(20, 40, kSize.width - 40, titleBar.height - 50)];
- textView.font = [UIFont scaleSize:Font17];
- textView.textColor = contentTextColor;
- textView.text = _dataDic[@"content"];
- if ([textView.text length] == 0) {
- textView.text = @"暂无详解";
- }
- textView.editable = NO;
- [titleBar addSubview:textView];
- }
- #pragma mark - 网络监测
- - (NSInteger)networkChanged:(NSNotification *)notification
- {
- RealReachability *reachability = (RealReachability *)notification.object;
- ReachabilityStatus status = [reachability currentReachabilityStatus];
- //如果变成没网 暂停 如果Wi-Fi突然换到流量 暂停视频 询问是否继续。其他不作处理
- if (_playerView.isPlaying) {
- if (status == RealStatusNotReachable) {
- ShowMsg(@"当前无网络连接");
- [self.playerView pause];
- }else if (status == RealStatusViaWWAN){
- if (!isGoOn4G) {
- [_playerView pause];
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的Wi-Fi已断开连接,继续播放将产生数据流量,是否继续播放?" delegate:self cancelButtonTitle:@"停止播放" otherButtonTitles:@"继续播放", nil];
- alert.tag = 2;
- [alert show];
- }
- }else{
- //wifi/未知情况
- }
- }
-
- return status;
- }
- -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
-
- if (alertView.tag == 1) {
- if (buttonIndex == alertView.cancelButtonIndex) {
- [self dismissViewControllerAnimated:YES completion:nil];
- }else if (buttonIndex == 1){
- if (self.goDownLoadBlock) {
- self.goDownLoadBlock();
- }
- [self dismissViewControllerAnimated:YES completion:nil];
- }else{
- [self.playerView updatePlayerWithURL:[NSURL URLWithString:_dataDic[@"videoPath"]]];
- isGoOn4G = YES;
- }
- }else if (alertView.tag == 2){
- if (buttonIndex == alertView.cancelButtonIndex) {
- //停止播放
- if (self.playerView.isPlaying) {
- [self.playerView pause];
- }
- }else{
- [self.playerView play];
- isGoOn4G = YES;
- }
- }
- }
- - (NSString *)getVideoFormat{
- NSString *format = [NSString stringWithFormat:@".%@",[[self.dataDic[@"videoPath"] componentsSeparatedByString:@"."] lastObject]];
- return format;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|