Created
November 12, 2014 11:22
-
-
Save priore/d45ffd2e9ea02c0d2f6e to your computer and use it in GitHub Desktop.
How to check the end of an audio (AVPlayer)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 | |
| } | |
| }]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment