xxTIGERxx
xxTIGERxx

Reputation: 1

audioPlayerDidFinishPlaying method is not fired in the CLI application on iOS

I am trying to make a CLI audio player in Objective-C on jailbroken iOS14.
But the audioPlayerDidFinishPlaying method is not fired.
I wrote some codes like this.

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#include <unistd.h>

@interface AVAPDelegate: NSObject<AVAudioPlayerDelegate>
@end

@implementation AVAPDelegate
-(void) audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
  NSLog(@"ok");
}
@end

int main(){
  AVAPDelegate *dele = [[AVAPDelegate alloc] init];
  AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:@"test.mp3"] error:nil];
  player.delegate = dele;
  [player prepareToPlay];
  [player play];

  while(player.isPlaying){
    sleep(1);
  }
  return 0;
}

Result: no output
What should I do?

Upvotes: 0

Views: 74

Answers (1)

xxTIGERxx
xxTIGERxx

Reputation: 1

I changed the code and finally got the "ok" output.

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@interface AVAPDelegate: NSObject<AVAudioPlayerDelegate>
@end

@implementation AVAPDelegate
-(void) audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
   NSLog(@"ok");
}
@end

int main(){
  AVAPDelegate *dele = [[AVAPDelegate alloc] init];
  AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:@"test.mp3"] error:nil];
  player.delegate = dele;
  [player prepareToPlay];
  [player play];

  [[NSRunLoop currentRunLoop] run];
  return 0;
}

Upvotes: 0

Related Questions