Is it possible to play parts of an audio file. So, i have one audio file with a lot of sounds. In this case, the One audio file is acting like an "ARRAY", holding many items. I want to separate parts of the audio by playing at {5:01 and stop at 6:08}
something like that. Is this possible? I am very knew to Xcode, so this might be a dumb question. Thanks. If there is anything you need, please comment below.
Asked
Active
Viewed 745 times
2

Anoop Vaidya
- 46,283
- 15
- 111
- 140

Hunter Mitchell
- 7,063
- 18
- 69
- 116
-
This is not relatd to xcode, which is an IDE. – Anoop Vaidya Mar 02 '13 at 04:19
-
It's definitely possible, since I've done it. I don't have the code at hand, though. Something like Murali's code, IIRC. – Hot Licks Mar 02 '13 at 04:39
2 Answers
5
Playing audio for certain duration is not available..But we can do this in following way.
-(void)Play
{
AVAudioPlayer *avPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:[FileDetailsRec valueForKey:@"Path"]] error:nil];
[avPlayer setCurrentTime:5.01f];
[avPlayer prepareToPlay];
[avPlayer play];
objTimer = [NSTimer scheduledTimerWithTimeInterval:1.07f target:self selector:@selector(stop) userInfo:nil repeats:NO];
}
-(void)stop
{
[objTimer invalidate];
[avPlayer stop];
}

Murali
- 1,869
- 1
- 14
- 22
-
-
Take an object for NsTimer and then in stop method just place this [objTimer invalidate]; http://stackoverflow.com/questions/15170518/how-to-stop-invalidate-nstimer – Murali Mar 02 '13 at 04:41
2
this one might be possible by Using AVAudioPlayer but i'm not sure about this one once see this reference class AVAudioPlayer in this class bu using below method you can get your requirement
- (BOOL)playAtTime:(NSTimeInterval)time and for stoping use NSTimer like
[NSTimer scheduledTimerWithTimeInterval:(place your time interval)
target:self
selector:@selector(stop)
userInfo:nil
repeats:NO];

Balu
- 8,470
- 2
- 24
- 41