1
votes

I have an avaudioplayer that loads a sound file and loops. The problem is that everytime the file loops, there is a pause/delay which makes music sound bad.

I found this question which had a similar issue, but is for 2 players. I have a single player that has a 1 second pause at each loop: AVAudioPlayer eliminating one second pause between sound files

Here is what my audio player setup looks like:

@interface HomeViewController ()

@property (strong, nonatomic) DataController *dataController;

@end

@implementation HomeViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.dataController = [DataController sharedInstance];

        [self createAndStartAudioPlayer];


}

- (void) viewWillAppear:(BOOL)animated{

        [self.dataController.player play];
}

- (void) createAndStartAudioPlayer {

    NSTimeInterval shortStartDelay = 0.01;            // seconds
    NSTimeInterval now = self.dataController.player.deviceCurrentTime;

    [self.dataController.player       playAtTime: now + shortStartDelay];

        NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"jingle-loop" ofType:@"mp3"];
        NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
        self.dataController.player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL fileTypeHint:AVFileTypeMPEGLayer3 error:nil];
        self.dataController.player.numberOfLoops = -1; //infinite

    [self.dataController.player prepareToPlay];


}

How do I stop this 1 second pause and play the loop like it is a continuous song?

1
when the file is played first time, is there delay too ?Teja Nandamuri
if there is delay in playing the file for first time, try to edit the audio file using audio editor like audacity and remove the white space before and after the actual audio.Sometimes there will be a fade in or fade out style added to audio file. See if it works or not.Teja Nandamuri

1 Answers

0
votes

Mr. T in the comments was in fact right. The solution was to fix the white space that is added automatically by garage band.