0

I just need to listen to the file slowly or quickly. Any help will be greatly appreciated

iGatiTech
  • 2,306
  • 1
  • 21
  • 45
marduck19
  • 54
  • 2
  • 11
  • `AVPlayer` can’t do that. Do you want the audio pitch to stay the same when adjusting the speed? – zoul Sep 19 '11 at 18:29
  • Check this [question](http://stackoverflow.com/questions/2350657/avaudioplayer-how-to-change-the-playback-speed-of-audio) – Youssef Sep 19 '11 at 18:32

3 Answers3

1

in Swift 3.0 it will be like this -

    audioP = try! AVAudioPlayer(contentsOf: URL(fileURLWithPath: selectedPath), fileTypeHint: "caf")
    audioP.enableRate = true
    audioP.prepareToPlay()
    audioP.rate = 1.5
    audioP.play()

Hope this helps :)

Shawon91
  • 200
  • 3
  • 9
1

AVAudioplayer can't do that, AVPlayer can.

       // play audio file as NSURL *url;
    NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]
                                                        forKey:AVURLAssetPreferPreciseDurationAndTimingKey];

    AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:options];
    NSString *tracksKey = @"tracks";
    [urlAsset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler:
     ^{

         // Completion handler block.
         dispatch_async(dispatch_get_main_queue(),
                        ^{
                            NSError *error = nil;
                            AVKeyValueStatus status = [urlAsset statusOfValueForKey:tracksKey error:&error];

                            if (status == AVKeyValueStatusLoaded) {
                                self.avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
                                [avPlayer play];

                                avPlayer.rate = 0.5;
                            }
                            else {
                                // You should deal with the error appropriately.
                                NSLog(@"The asset's tracks were not loaded:\n%@", [error localizedDescription]);

                            }

                        });
     }];
Daniel Broad
  • 2,512
  • 18
  • 14
  • This will give you horrible sound quality. http://stackoverflow.com/questions/19374839/how-to-play-60fps-h-264-video-with-clean-audio-at-30fps – openfrog Oct 15 '13 at 06:49
1

thanks but I have solved it as follows:

Install cocos2d http://www.cocos2d-iphone.org/download

[[SimpleAudioEngine sharedEngine] playEffect: (NSString *) pitch (float32) pan (float32) gain (float32)]

its simple and works....

marduck19
  • 54
  • 2
  • 11