renzifeng / ZFPlayer

Support customization of any player SDK and control layer(支持定制任何播放器SDK和控制层)
MIT License
7.07k stars 1.75k forks source link

ZFPlayer可以自定义播放视频总长时间么? #899

Closed ljssafe closed 4 years ago

ljssafe commented 4 years ago

需求是 播放预览 但是总长时间需要显示整个视频的总长时间 但是预览的url是3分钟 实际完整视频27分钟这样子 所以需要自定义播放器的总长时间而不是获取URL里的

ljssafe commented 4 years ago

@weakify(self); self.player.currentPlayerManager.playerPlayTimeChanged = ^(id _Nonnull asset, NSTimeInterval currentTime, NSTimeInterval duration) { @strongify(self);

                if ([self.player.controlView respondsToSelector:@selector(videoPlayer:currentTime:totalTime:)]) {
                    [self.player.controlView videoPlayer:self.player currentTime:currentTime totalTime:itemsets.duration];
                }
            };

重新实现了该回调,建议可以把这个丢个属性出来方便 这种需求,毕竟这种情况应该还是蛮常见的

ljssafe commented 4 years ago

@renzifeng 我已经改好文件了 新增了个videoTotalTime 不影响原有功能 文件要传你更新一把不 🙃 #

ljssafe commented 4 years ago

// // ZFPlayerCustomControlView.m // Wisburg // // Created by Brandy on 2019/11/15. // Copyright © 2019 brandy. All rights reserved. //

import "ZFPlayerCustomControlView.h"

import <AVKit/AVKit.h>

import <AVFoundation/AVFoundation.h>

import <ZFPlayer/UIView+ZFFrame.h>

import <ZFPlayer/ZFSliderView.h>

import <ZFPlayer/ZFUtilities.h>

import <ZFPlayer/UIImageView+ZFCache.h>

import <MediaPlayer/MediaPlayer.h>

import <ZFPlayer/ZFVolumeBrightnessView.h>

if __has_include(<ZFPlayer/ZFPlayer.h>)

import <ZFPlayer/ZFPlayer.h>

else

import "ZFPlayer.h"

endif

@interface ZFPlayerCustomControlView ()

/// 竖屏控制层的View @property (nonatomic, strong) ZFPortraitCustomControlView portraitControlView; /// 横屏控制层的View @property (nonatomic, strong) ZFLandScapeCustomControlView landScapeControlView; /// 加载loading @property (nonatomic, strong) ZFSpeedLoadingView activity; /// 快进快退View @property (nonatomic, strong) UIView fastView; /// 快进快退进度progress @property (nonatomic, strong) ZFSliderView fastProgressView; /// 快进快退时间 @property (nonatomic, strong) UILabel fastTimeLabel; /// 快进快退ImageView @property (nonatomic, strong) UIImageView fastImageView; /// 加载失败按钮 @property (nonatomic, strong) UIButton failBtn; /// 底部播放进度 @property (nonatomic, strong) ZFSliderView bottomPgrogress; /// 封面图 @property (nonatomic, strong) UIImageView coverImageView; /// 是否显示了控制层 @property (nonatomic, assign, getter=isShowing) BOOL showing; /// 是否播放结束 @property (nonatomic, assign, getter=isPlayEnd) BOOL playeEnd;

@property (nonatomic, assign) BOOL controlViewAppeared;

@property (nonatomic, assign) NSTimeInterval sumTime;

@property (nonatomic, strong) dispatch_block_t afterBlock;

@property (nonatomic, strong) ZFSmallFloatControlView *floatControlView;

@property (nonatomic, strong) ZFVolumeBrightnessView *volumeBrightnessView;

@property (nonatomic, strong) UIImageView *bgImgView;

@property (nonatomic, strong) UIView *effectView;

@end

@implementation ZFPlayerCustomControlView

@synthesize player = _player;

/// 添加所有子控件

/// 取消延时隐藏controlView的方法

/// 隐藏控制层

/// 显示控制层

/// 音量改变的通知

pragma mark - Public Method

/// 重置控制层

/// 设置标题、封面、全屏模式

/// 设置标题、封面、默认占位图、全屏模式

/// 设置标题、UIImage封面、全屏模式

pragma mark - ZFPlayerControlViewDelegate

/// 手势筛选,返回NO不响应该手势

/// 单击手势事件

/// 双击手势事件

/// 开始滑动手势事件

/// 滑动中手势事件

/// 滑动结束手势事件

/// 捏合手势事件,这里改变了视频的填充模式

/// 准备播放

/// 播放状态改变

/// 加载状态改变

/// 播放进度改变回调

/// 缓冲改变回调

/// 视频view即将旋转

/// 视频view已经旋转

/// 锁定旋转方向

/// 列表滑动时视频view已经显示

/// 列表滑动时视频view已经消失

pragma mark - Private Method

/// 隐藏快进视图

/// 加载失败

pragma mark - setter

pragma mark - getter

@end

// // ZFPortraitCustomControlView.m // Wisburg // // Created by Brandy on 2019/11/15. // Copyright © 2019 brandy. All rights reserved. //

import "ZFPortraitCustomControlView.h"

import <ZFPlayer/UIView+ZFFrame.h>

import <ZFPlayer/ZFUtilities.h>

if __has_include(<ZFPlayer/ZFPlayer.h>)

import <ZFPlayer/ZFPlayer.h>

else

import "ZFPlayer.h"

endif

@interface ZFPortraitCustomControlView () /// 底部工具栏 @property (nonatomic, strong) UIView bottomToolView; /// 顶部工具栏 @property (nonatomic, strong) UIView topToolView; /// 标题 @property (nonatomic, strong) UILabel titleLabel; /// 播放或暂停按钮 @property (nonatomic, strong) UIButton playOrPauseBtn; /// 播放的当前时间 @property (nonatomic, strong) UILabel currentTimeLabel; /// 滑杆 @property (nonatomic, strong) ZFSliderView slider; /// 视频总时间 @property (nonatomic, strong) UILabel totalTimeLabel; /// 全屏按钮 @property (nonatomic, strong) UIButton fullScreenBtn;

@property (nonatomic, assign) BOOL isShow;

@end

@implementation ZFPortraitCustomControlView

pragma mark - ZFSliderViewDelegate

pragma mark - action

/// 根据当前播放状态取反

pragma mark - 添加子控件约束

pragma mark -

/* 重置ControlView /

/// 调节播放进度slider和当前时间更新

/// 滑杆结束滑动

pragma mark - getter

@end

// // ZFLandScapeCustomControlView.m // Wisburg // // Created by Brandy on 2019/11/15. // Copyright © 2019 brandy. All rights reserved. //

import "ZFLandScapeCustomControlView.h"

import <ZFPlayer/UIView+ZFFrame.h>

import <ZFPlayer/ZFUtilities.h>

if __has_include(<ZFPlayer/ZFPlayer.h>)

import <ZFPlayer/ZFPlayer.h>

else

import "ZFPlayer.h"

endif

@interface ZFLandScapeCustomControlView ()

/// 顶部工具栏 @property (nonatomic, strong) UIView topToolView; /// 返回按钮 @property (nonatomic, strong) UIButton backBtn; /// 标题 @property (nonatomic, strong) UILabel titleLabel; /// 底部工具栏 @property (nonatomic, strong) UIView bottomToolView; /// 播放或暂停按钮 @property (nonatomic, strong) UIButton playOrPauseBtn; /// 播放的当前时间 @property (nonatomic, strong) UILabel currentTimeLabel; /// 滑杆 @property (nonatomic, strong) ZFSliderView slider; /// 视频总时间 @property (nonatomic, strong) UILabel totalTimeLabel; /// 锁定屏幕按钮 @property (nonatomic, strong) UIButton *lockBtn;

@property (nonatomic, assign) BOOL isShow;

@end

@implementation ZFLandScapeCustomControlView

pragma mark - ZFSliderViewDelegate

pragma mark -

/// 重置ControlView

/// 调节播放进度slider和当前时间更新

/// 滑杆结束滑动

pragma mark - action

/// 根据当前播放状态取反

pragma mark - getter

@end