简体   繁体   中英

avplayer pause or stop notification based on the rate

I need to send notifications when the AVPlayer is Play/Paused and Stopped. For play and pause below is the code

if (self.player.rate > 0.0f) {
       NSLog(@" Playing ..")
}

if (self.player.rate == 0.0f) {
       NSLog(@" Paused ..")
}

But for stopped also the rate = 0.0 then is there any other property or way to identify the difference between paused and stopped. For both, paused and stopped the rate = 0.0 and hence need another way for it.

Thanks

There is no stop command for an AVPlayer. So there is no such thing as stopped as distinct from paused. Either the rate is zero (not playing) or it is more than zero (playing).

You can distinguish where the player is within its item ( currentTime ) so you can tell whether we are at the start, end, or middle; and you can arrange to be notified periodically during play or when the end is reached.

Apart from that, there are no distinctions to be drawn.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM