Created
May 2, 2014 17:27
-
-
Save dmur/bca0d281a6c68b5f3b30 to your computer and use it in GitHub Desktop.
This file contains 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
- (AVAudioPlayer *)playWaveformNamed:(NSString *)fileName | |
withCompletionHandler:(void (^)(void))completionHandler | |
{ | |
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"wav"]; | |
NSURL *fileURL = [NSURL fileURLWithPath:filePath]; | |
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL | |
error:nil]; | |
audioPlayer.delegate = self; | |
[audioPlayer play]; | |
AVURLAsset *audioAsset = [AVURLAsset URLAssetWithURL:fileURL options:nil]; | |
CMTime audioDuration = audioAsset.duration; | |
float audioDurationSeconds = CMTimeGetSeconds(audioDuration); | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(audioDurationSeconds * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
if (completionHandler) completionHandler(); | |
}); | |
return audioPlayer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment