判断AVPlayer播放状态
生活随笔
收集整理的這篇文章主要介紹了
判断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.@discussionSetting 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播放状态的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux怎么卸载vsftpd软件,vs
- 下一篇: oracle12c备份和恢复,oracl