我是靠谱客的博主 疯狂雪糕,这篇文章主要介绍判断AVPlayer播放状态,现在分享给大家,希望可以做个参考。

AVPlayer有一个AVPlayerItem类型的对象currentItem.

typedef NS_ENUM(NSInteger, AVPlayerItemStatus) {
	/// 未知状态
	AVPlayerItemStatusUnknown,
	/// 准备好播放(播放也是这个)
	AVPlayerItemStatusReadyToPlay,
	/// 播放失败
	AVPlayerItemStatusFailed
};

1.首先我们监听AVPlayerratekeyPath

如果直接判断status == AVPlayerItemStatusReadyToPlay的话,停止状态也可能是判断成播放.所以我们就要使用AVPlayer里头的一个rate属性了

/*!
 @property		rate
 @abstract		Indicates the desired rate of playback; 0.0 means "paused", 1.0 indicates a desire to play at the natural rate of the current item.
 @discussion
 Setting the value of rate to 0.0 pauses playback, causing the value of timeControlStatus to change to AVPlayerTimeControlStatusPaused.
 Setting the rate to a non-zero value causes the value of timeControlStatus to become either AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate or AVPlayerTimeControlStatusPlaying, depending on whether sufficient media data has been buffered for playback to occur and whether the player's default behavior of waiting in order to minimize stalling is permitted. See discussion of AVPlayerTimeControlStatus for more details.
 
 AVPlayer can reset the desired rate to 0.0 when a change in overall state requires playback to be halted, such as when an interruption occurs on iOS, as announced by AVAudioSession, or when the playback buffer becomes empty and playback stalls while automaticallyWaitsToMinimizeStalling is NO.

 The effective rate of playback may differ from the desired rate even while timeControlStatus is AVPlayerTimeControlStatusPlaying, if the processing algorithm in use for managing audio pitch requires quantization of playback rate. For information about quantization of rates for audio processing, see AVAudioProcessingSettings.h. You can always obtain the effective rate of playback from the currentItem's timebase; see the timebase property of AVPlayerItem.
 */
@property (nonatomic) float rate;

那么我们只需要判断rate == 0.0.如果是0的话就是暂停否则就是播放.

最后

以上就是疯狂雪糕最近收集整理的关于判断AVPlayer播放状态的全部内容,更多相关判断AVPlayer播放状态内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部