PLVMediaPlayerCore
Objective-C
@interface PLVMediaPlayerCore : NSObject
#pragma mark - [ 属性 ]
#pragma mark 可配置项
/// delegate
@property (nonatomic, weak) id <PLVMediaPlayerCoreDelegate> coreDelegate;
/// 播放器是否自动播放
@property (nonatomic, assign) BOOL autoPlay;
/// App进入后台时,是否暂停 主播放器 播放
///
/// @note 若需支持‘后台播放’,则需同时在 TARGETS - Capability - Background Modes 中勾选 “Audio, AirPlay, and Picture in Picture”;
/// YES:关闭后台播放 NO:开启后台播放;默认值 NO;
/// 从后台进入前台时,主播放器不会自动恢复播放。请根据业务需要,自行调用恢复播放方法;
@property (nonatomic, assign) BOOL pausePlayerInBackground;
/// 开启后台模式,启动画中画播放功能, 默认NO
@property (nonatomic, assign) BOOL enablePIPInBackground;
#pragma mark 数据
/// 视频缓存时长
@property (nonatomic, readonly) int64_t videoCacheDuration;
/// 视频下载速率
@property (nonatomic, readonly) int64_t originalTcpSpeed;
/// 视频下载速率字符串 (示例 "100KB/s")
@property (nonatomic, readonly) NSString * tcpSpeed;
/// 视频大小
@property (nonatomic, readonly) CGSize naturalSize;
/// 视频流量
@property (nonatomic, readonly) CGFloat flow;
/// 当前播放时间点 (单位:秒)
@property (nonatomic, readonly) NSTimeInterval currentPlaybackTime;
/// 视频总时长
@property (nonatomic, readonly) NSTimeInterval duration;
/// 当前已缓存时长
@property (nonatomic, readonly) NSTimeInterval playableDuration;
/// 当前倍速
@property (nonatomic, assign, readonly) CGFloat currentSpeed;
#pragma mark 状态
/// 播放器播放状态
@property (nonatomic, assign, readonly) PLVPlaybackState playbackState;
/// 播放器加载状态
@property (nonatomic, assign, readonly) PLVPlayerLoadState playerLoadState;
/// 播放器的缩放模式,默认为IJKMPMovieScalingModeAspectFit
@property (nonatomic, assign, readonly) IJKMPMovieScalingMode scalingMode;
/// 是否正在播放中
@property (nonatomic, assign, readonly) BOOL playing;
#pragma mark 功能对象
/// 由外部传入的,负责承载播放器画面的父视图
///
/// @note 需调用 [setupDisplaySuperview:] 方法来设置
@property (nonatomic, strong, readonly) UIView * displaySuperview;
#pragma mark - [ 方法 ]
#pragma mark 通用
/// 播放主体内容
///
/// @note 初始化播放器;
///
/// @param contentURL 媒体地址
/// @param options 播放器配置选项
- (void)initPlayerWithContentURL:(NSURL *)contentURL withOptions:(PLVOptions *)options;
/// 初始化私有加密播放器
- (void)initPlayerWithPrefixUrlString:(NSString *)prefixURLString urlData:(NSData *)urlData withOptions:(PLVOptions *)options;
/// 设置 承载播放器画面 的父视图
///
/// @param displayeSuperview 承载播放器画面的父视图
- (void)setupDisplaySuperview:(UIView *)displayeSuperview;
/// 设置 播放器 的缩放模式
///
/// @param scalingMode 缩放模式,默认为IJKMPMovieScalingModeAspectFit
- (void)setupScalingMode:(IJKMPMovieScalingMode)scalingMode;
/// 清理 主播放器
- (void)clearMainPlayer;
/// 清理 全部播放器
- (void)clearAllPlayer;
/// 暂停 主播放器 播放
- (void)pause;
/// 静音 主播放器
- (void)mute;
/// 取消静音 主播放器
- (void)cancelMute;
/// 开始 主播放器 播放
- (void)play;
/// 主播放器 视频跳至某个时间点
- (void)seekToTime:(NSTimeInterval)toTime;
/// 主播放器 切换倍速 (范围值 0.0~2.0)
- (void)switchSpeedRate:(CGFloat)toSpeed;
/// 当前时间截图
- (UIImage *)snapshot;
@end
Swift
class PLVMediaPlayerCore : NSObject
Undocumented
-
delegate
Declaration
Objective-C
@property (nonatomic, weak) id<PLVMediaPlayerCoreDelegate> _Nullable coreDelegate;Swift
weak var coreDelegate: (any PLVMediaPlayerCoreDelegate)? { get set } -
播放器是否自动播放
Declaration
Objective-C
@property (nonatomic) BOOL autoPlay;Swift
var autoPlay: Bool { get set } -
App进入后台时,是否暂停 主播放器 播放
Note
若需支持‘后台播放’,则需同时在 TARGETS - Capability - Background Modes 中勾选 “Audio, AirPlay, and Picture in Picture”; YES:关闭后台播放 NO:开启后台播放;默认值 NO; 从后台进入前台时,主播放器不会自动恢复播放。请根据业务需要,自行调用恢复播放方法;Declaration
Objective-C
@property (nonatomic) BOOL pausePlayerInBackground;Swift
var pausePlayerInBackground: Bool { get set } -
开启后台模式,启动画中画播放功能, 默认NO
Declaration
Objective-C
@property (nonatomic) BOOL enablePIPInBackground;Swift
var enablePIPInBackground: Bool { get set }
-
视频缓存时长
Declaration
Objective-C
@property (nonatomic, readonly) int64_t videoCacheDuration;Swift
var videoCacheDuration: Int64 { get } -
视频下载速率
Declaration
Objective-C
@property (nonatomic, readonly) int64_t originalTcpSpeed;Swift
var originalTcpSpeed: Int64 { get } -
视频下载速率字符串 (示例 “100KB/s”)
Declaration
Objective-C
@property (nonatomic, readonly) NSString *_Nonnull tcpSpeed;Swift
var tcpSpeed: String { get } -
视频大小
Declaration
Objective-C
@property (nonatomic, readonly) CGSize naturalSize;Swift
var naturalSize: CGSize { get } -
视频流量
Declaration
Objective-C
@property (nonatomic, readonly) CGFloat flow;Swift
var flow: Double { get } -
当前播放时间点 (单位:秒)
Declaration
Objective-C
@property (nonatomic, readonly) NSTimeInterval currentPlaybackTime;Swift
var currentPlaybackTime: TimeInterval { get } -
视频总时长
Declaration
Objective-C
@property (nonatomic, readonly) NSTimeInterval duration;Swift
var duration: TimeInterval { get } -
当前已缓存时长
Declaration
Objective-C
@property (nonatomic, readonly) NSTimeInterval playableDuration;Swift
var playableDuration: TimeInterval { get } -
当前倍速
Declaration
Objective-C
@property (nonatomic, readonly) CGFloat currentSpeed;Swift
var currentSpeed: Double { get }
-
播放器播放状态
Declaration
Objective-C
@property (nonatomic, readonly) PLVPlaybackState playbackState;Swift
var playbackState: PLVPlaybackState { get } -
播放器加载状态
Declaration
Objective-C
@property (nonatomic, readonly) PLVPlayerLoadState playerLoadState;Swift
var playerLoadState: PLVPlayerLoadState { get } -
播放器的缩放模式,默认为IJKMPMovieScalingModeAspectFit
Declaration
Objective-C
@property (nonatomic, readonly) int scalingMode;Swift
var scalingMode: Int32 { get } -
是否正在播放中
Declaration
Objective-C
@property (nonatomic, readonly) BOOL playing;Swift
var playing: Bool { get }
-
由外部传入的,负责承载播放器画面的父视图
Note
需调用 [setupDisplaySuperview:] 方法来设置Declaration
Objective-C
@property (nonatomic, strong, readonly) UIView * displaySuperview
-
播放主体内容
Note
初始化播放器;
Declaration
Objective-C
- (void)initPlayerWithContentURL:(nonnull NSURL *)contentURL withOptions:(id)options;Swift
func initPlayer(withContentURL contentURL: URL, withOptions options: Any!)Parameters
contentURL媒体地址
options播放器配置选项
-
初始化私有加密播放器
Declaration
Objective-C
- (void)initPlayerWithPrefixUrlString:(nonnull NSString *)prefixURLString urlData:(nonnull NSData *)urlData withOptions:(id)options;Swift
func initPlayer(withPrefixUrlString prefixURLString: String, urlData: Data, withOptions options: Any!) -
设置 承载播放器画面 的父视图
Declaration
Objective-C
- (void)setupDisplaySuperview:(id)displayeSuperview;Swift
func setupDisplaySuperview(_ displayeSuperview: Any!)Parameters
displayeSuperview承载播放器画面的父视图
-
设置 播放器 的缩放模式
Declaration
Objective-C
- (void)setupScalingMode:(id)scalingMode;Swift
func setupScalingMode(_ scalingMode: Any!)Parameters
scalingMode缩放模式,默认为IJKMPMovieScalingModeAspectFit
-
清理 主播放器
Declaration
Objective-C
- (void)clearMainPlayer;Swift
func clearMainPlayer() -
清理 全部播放器
Declaration
Objective-C
- (void)clearAllPlayer;Swift
func clearAllPlayer() -
暂停 主播放器 播放
Declaration
Objective-C
- (void)pause;Swift
func pause() -
静音 主播放器
Declaration
Objective-C
- (void)mute;Swift
func mute() -
取消静音 主播放器
Declaration
Objective-C
- (void)cancelMute;Swift
func cancelMute() -
开始 主播放器 播放
Declaration
Objective-C
- (void)play;Swift
func play() -
主播放器 视频跳至某个时间点
Declaration
Objective-C
- (void)seekToTime:(NSTimeInterval)toTime;Swift
func seek(toTime: TimeInterval) -
主播放器 切换倍速 (范围值 0.0~2.0)
Declaration
Objective-C
- (void)switchSpeedRate:(CGFloat)toSpeed;Swift
func switchSpeedRate(_ toSpeed: Double) -
当前时间截图
Declaration
Objective-C
- (id)snapshot;Swift
func snapshot() -> Any!
View on GitHub
PLVMediaPlayerCore Class Reference