Created
November 21, 2012 10:19
-
-
Save metaphox/4124125 to your computer and use it in GitHub Desktop.
play back from - to snippet
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
| 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