hafedh
hafedh

Reputation: 539

Check if AVQueuePlayer is playing?

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.

Upvotes: 4

Views: 1371

Answers (2)

Sahil Kapoor
Sahil Kapoor

Reputation: 11773

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;
}

Upvotes: 3

Khaled Annajar
Khaled Annajar

Reputation: 16552

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
}

Upvotes: 0

Related Questions