2

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.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
Hunter Mitchell
  • 7,063
  • 18
  • 69
  • 116

2 Answers2

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
  • Thanks, this helps a lot. Is there a way to reset the timer? – Hunter Mitchell Mar 02 '13 at 04:38
  • 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