1

I looking for some solution for waiting until SuperpoweredAdvancedAudioPlayer open the file. I make ios objective-c application where I want to play multiple tracks at the same time. But when I try start tracks in this way:

    player1->open([[[NSBundle mainBundle] pathForResource:[[tracksNamesBigArray objectAtIndex:row] objectAtIndex:0]ofType:@"mp3"] fileSystemRepresentation]);
        player1->play(true);

    player2->open([[[NSBundle mainBundle] pathForResource:[[tracksNamesBigArray objectAtIndex:row] objectAtIndex:1] ofType:@"mp3"] fileSystemRepresentation]);
    player2->play(true);

    player3->open([[[NSBundle mainBundle] pathForResource:[[tracksNamesBigArray objectAtIndex:row] objectAtIndex:2] ofType:@"mp3"] fileSystemRepresentation]);
    player3->play(true);

    player4->open([[[NSBundle mainBundle] pathForResource:[[tracksNamesBigArray objectAtIndex:row] objectAtIndex:3] ofType:@"mp3"] fileSystemRepresentation]);
    player4->play(true);

or when I wrap this in functions and make something like this:

  [self openPlayers:row]
  [self playAll];

It doesn't start play perfectly in the same time, one or 2 last tracks starts with .5s-.8s delay(in first example delay is larger than in second). How to wait until open is successful and then start to play? I did't find any function for that in superpowered documentation.

MaSza
  • 435
  • 7
  • 22

2 Answers2

2

Audio processing happens in the audio processing callback, which is called periodically in a high priority thread by the audio stack.

I'm guessing you are calling the play() methods in another thread, perhaps the main thread. When you call those methods, the audio processing callback may fire in between, making a delay of one buffer size.

The solution is calling the play() methods at the beginning of the audio processing callback.

Gabor Szanto
  • 1,329
  • 8
  • 12
2

To check when SuperpoweredAdvancedAudioPlayer open and load files I must use SuperpoweredAdvancedPlayerEvent_LoadSuccess in playerEventCallback. Then sync start of players are much better.

This is my new playerEventCallback:

void playerEventCallback1(void *clientData, SuperpoweredAdvancedAudioPlayerEvent event, void *value) {
    RootViewController *self = (__bridge RootViewController *)clientData;
    switch(event){
        case SuperpoweredAdvancedAudioPlayerEvent_LoadSuccess:{
            RootViewController *self = (__bridge RootViewController *)clientData;
            NSLog(@"Player1 load success");
            self->loadIndicator++;
            break;
        }
        case SuperpoweredAdvancedAudioPlayerEvent_EOF:{
            self->player1->pause();
            self->player1->setPosition(0, true, false);
            break;} 
    }
}
MaSza
  • 435
  • 7
  • 22