[Objective-C] How to check the end of an audio (AVPlayer)

// How to check the end of an audio
AVAsset *asset = [AVURLAsset URLAssetWithURL:your-url options:nil];
AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset];
self.player = [AVPlayer playerWithPlayerItem:anItem];
    __weak typeof(self) wself = self;
    CMTime interval = CMTimeMake(1, 1);
    id observer = [self.soundPlayer addPeriodicTimeObserverForInterval:interval queue:dispatch_get_main_queue() usingBlock:^(CMTime time) {
        // controlla la fine dell'audio
        CMTime duration = CMTimeConvertScale(wself.player.currentItem.duration, wself.player.currentTime.timescale, kCMTimeRoundingMethod_Default);
        if (CMTIME_COMPARE_INLINE(duration, ==, wself.player.currentTime)) {
            // TODO: your code here

Copyright © 1996-2020 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581.