日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

判断AVPlayer播放状态

發布時間:2023/12/31 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 判断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播放状态的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。