Skip to content

Instantly share code, notes, and snippets.

@metaphox
Created November 21, 2012 10:19
Show Gist options
  • Select an option

  • Save metaphox/4124125 to your computer and use it in GitHub Desktop.

Select an option

Save metaphox/4124125 to your computer and use it in GitHub Desktop.
play back from - to snippet
NSString *myAudioFileInBundle = @"words.mp3";
NSTimeInterval wordStartsAt = 1.8;
NSTimeInterval wordEndsAt = 6.5;
NSString *filePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:myAudioFileInBundle];
NSURL *myFileURL = [NSURL fileURLWithPath:filePath];
AVAudioPlayer *myPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:myFileURL error:nil];
if (myPlayer) {
[myPlayer setCurrentTime:wordStartsAt];
[myPlayer prepareToPlay];
[myPlayer play];
[NSTimer
scheduledTimerWithTimeInterval:wordEndsAt-wordStartsAt
target:myPlayer.autorelease
selector:@selector(stop)
userInfo:nil
repeats:NO];
}
//http://stackoverflow.com/questions/7105786/ios-stop-audio-playback-at-certain-time-avaudioplayer-end-time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment