4

I'm trying to develop multi files audio player so I used AVQueuePlayer, I need to check whenever the player is playing a sound or paused?

For AvAudioPlayer, I have the property "isPlaying", but for AVQueuePlayer how to check it? Thanks.

hafedh
  • 539
  • 1
  • 9
  • 26

2 Answers2

3

You can check if AVQueuePlayer is playing by checking if rate of queue player object is more than 0

-(BOOL)isPlaying {
    return self.queuePlayer.rate > 0;
}
Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87
0

You can use this method

addBoundaryTimeObserverForTimes: 

to know when the player starts playing some file as explained in this url: http://www.artermobilize.com/blog/2014/02/28/detect-when-audio-playback-begins-with-avplayer-in-ios/

also you can use this code to know when the playback is finished:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playerItemDidReachEnd:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:nil];

- (void)playerItemDidReachEnd:(NSNotification *)notification
{
    // your code here
}
Khaled Annajar
  • 15,542
  • 5
  • 34
  • 45