AVPlayer 재생 상태 판단

2032 단어 오디오 비디오
AVPlayer에는 AVPlayerItem 유형의 객체가 있습니다currentItem.
typedef NS_ENUM(NSInteger, AVPlayerItemStatus) {
	///  
	AVPlayerItemStatusUnknown,
	///  ( )
	AVPlayerItemStatusReadyToPlay,
	///  
	AVPlayerItemStatusFailed
};

1. 우선 AVPlayer rate keyPath 감청


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;

그럼 저희는 레이트==0.0만 판단하면 돼요.0이면 멈추고 아니면 틀어.

좋은 웹페이지 즐겨찾기