ZFPlayer 全屏、橫豎屏使用小記


關於這個庫大家都不陌生,下面小結下自己使用過程中的經驗,主要是關於全屏橫豎屏的幾個小點。

使用cell上直接播放的創建方式(先小屏播放,然后點擊全屏按鈕),全屏后完全取決於外部設置的全屏模式(強制改變后會有問題)

_player = [ZFPlayerController playerWithScrollView:self.tableView playerManager:playerManager containerViewTag:100];

使用普通模式實現下面的分享有效果

 _player = [[ZFPlayerController alloc] initWithPlayerManager:playerManager containerView:[UIApplication sharedApplication].keyWindow];

 

全屏的兩種方式

1、ZFPlayerController

 [self.player enterFullScreen:YES animated:NO];

全屏  ZFPlayerControlView設置的全屏模式必須建立在player存在的情況下

2、ZFPlayerControlView

 fullScreenOnly

 全屏,  豎屏有全屏按鈕 無返回按鈕 必須到橫屏才有返回按鈕 設置的模式不再受影響

 

橫豎屏的兩個影響屬性(ZFPlayerController)

1、 lockedScreen 默認NO

鎖定屏幕, 什么操作都添加不了, 設置為YES時不論系統是否鎖定豎屏 ,都可以按照預定的橫豎屏顯示

2、allowOrentitaionRotation 默認YES

是否允許播放器旋轉 ,可以正常自定義添加標題、時間、返回按鈕等等 ,設置為NO時不論系統是否鎖定豎屏, 都可以按照預定的橫豎屏顯示

設置為YES時,會根據手機旋轉方向自動調整,但初始化時會按照自定義的方向初始化

 

- (ZFPlayerController *)player {
    if (!_player) {
        
        ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];

        _player = [[ZFPlayerController alloc] initWithPlayerManager:playerManager containerView:[UIApplication sharedApplication].keyWindow];
        _player.controlView = self.controlView;
        _player.disableGestureTypes = ZFPlayerDisableGestureTypesDoubleTap | ZFPlayerDisableGestureTypesPan | ZFPlayerDisableGestureTypesPinch;
        _player.WWANAutoPlay = YES;
//        鎖定屏幕 什么操作都添加不了
//        _player.lockedScreen = YES;
//        不允許屏幕旋轉
        _player.allowOrentitaionRotation = NO;
        @weakify(self)
        _player.playerLoadStateChanged = ^(id<ZFPlayerMediaPlayback>  _Nonnull asset, ZFPlayerLoadState loadState) {
            if (loadState == ZFPlayerLoadStatePlaythroughOK) {
                [UIView animateWithDuration:0.5 animations:^{
                    @strongify(self)
                    self.controlView.backgroundColor = [UIColor clearColor];
                }];
            }
        };
    }
    return _player;
}

- (ZFPlayerControlView *)controlView {
    if (!_controlView) {
        _controlView = [[ZFPlayerControlView alloc] init];
//      全屏  豎屏有全屏按鈕 無返回按鈕 必須到橫屏才有返回按鈕
//        _controlView.fullScreenOnly = YES;
    }
    return _controlView;
}

#pragma mark - Event
- (void)playVideo:(NSString *) videoUrl
 videoSnapshotUrl:(NSString *) videoSnapshotUrl {
    if (!videoUrl.length) {
        return;
    }
    
    if (self.controlView) {
           self.controlView = nil;
       }
    self.controlView.backgroundColor = [UIColor blackColor];
    
    
    if (self.player) {
        self.player = nil;
    }
    
    @weakify(self)
    self.player.gestureControl.singleTapped = ^(ZFPlayerGestureControl * _Nonnull control) {
        @strongify(self)
        [UIView animateWithDuration:0.2 animations:^{
            self.player.containerView.alpha = 0.5;
        }completion:^(BOOL finished) {
            [self.player stop];
            self.player.containerView.alpha = 1;
            self.player = nil;

        }];

    };

    self.player.playerDidToEnd = ^(id  _Nonnull asset) {
        @strongify(self)
        [self.player.currentPlayerManager replay];
    };
// [self.player enterFullScreen:YES animated:NO]; 情況下必須放到這里 不然會失效  _controlView.fullScreenOnly = YES; 情況下不需要這樣 但是豎屏無法返回 必須到橫屏才有返回按鈕
    [self.controlView showTitle:@""
    coverURLString:videoSnapshotUrl
    fullScreenMode: ZFFullScreenModePortrait];
    [self.player enterFullScreen:YES animated:NO];
    self.player.currentPlayerManager.assetURL = [NSURL URLWithString:videoUrl];
   
   
}

- (void)playVideo:(NSString *) videoUrl
 videoSnapshotUrl:(NSString *) videoSnapshotUrl
        videoName:(NSString *) videoName
      imageFormat:(iComeImageFormat) imageFormat{
    if (!videoUrl.length) {
         return;
     }
     
     if (self.controlView) {
         self.controlView = nil;
     }
     self.controlView.backgroundColor = [UIColor blackColor];
    
     @weakify(self)
     self.controlView.backBtnClickCallback = ^{
        @strongify(self)
         [UIView animateWithDuration:0.2 animations:^{
             self.player.containerView.alpha = 0.5;
         }completion:^(BOOL finished) {

             [self.player stop];
             self.player.containerView.alpha = 1;
             self.player = nil;

         }];
    };
    
     if (self.player) {
         self.player = nil;
     }
    
    self.player.playerDidToEnd = ^(id  _Nonnull asset) {
        @strongify(self)
        [self.player.currentPlayerManager seekToTime:0 completionHandler:^(BOOL finished) {
            [self.player.currentPlayerManager pause];
        }];
    };
    
    [self.controlView showTitle:videoName
    coverURLString:videoSnapshotUrl
    fullScreenMode: (imageFormat == iComeImageFormatVertical ? ZFFullScreenModePortrait : ZFFullScreenModeLandscape)];
    [self.player enterFullScreen:YES animated:NO];
    self.player.currentPlayerManager.assetURL = [NSURL URLWithString:videoUrl];
}

- (void)playVideo:(NSString *) videoPath
       coverImage:(UIImage *) coverImage {
    
    if (!videoPath.length) {
        return;
    }
    
    if (self.controlView) {
        self.controlView = nil;
    }
    
    if (self.player) {
       self.player = nil;
    }
    
    @weakify(self)
    self.player.gestureControl.singleTapped = ^(ZFPlayerGestureControl * _Nonnull control) {
        @strongify(self)
        [UIView animateWithDuration:0.2 animations:^{
            self.player.containerView.alpha = 0.5;
        }completion:^(BOOL finished) {
            [self.player stop];
            self.player.containerView.alpha = 1;
            self.player = nil;

        }];

    };

    self.player.playerDidToEnd = ^(id  _Nonnull asset) {
        @strongify(self)

        [self.player.currentPlayerManager replay];
    };
    
    [self.controlView showTitle:@""
        coverImage:coverImage
    fullScreenMode:ZFFullScreenModePortrait];
    [self.player enterFullScreen:YES animated:NO];
    self.player.currentPlayerManager.assetURL = [NSURL fileURLWithPath:videoPath];
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM