Denis
Denis

Reputation: 795

Using AudioKit with Objective-C

I would like to add waveform plot features to my sound recorder/player, using Objective-C. I discovered the AudioKit 4 which seems a great framework, and I imported the AudioKit & AudioKitUI frameworks from audiokit.io website. I am using Xcode 9 with iOS10.0 target. Unfortunately I cannot initialize some classes from the AudioKit in my objective-C code... For example, to create an AKAudioPlayer instance, I use:

AKAudioFile *audioFile = [[AKAudioFile alloc] initForReading: myURL error:&error];  
AKAudioPlayer* playerAK = [[AKAudioPlayer alloc] initWithFile:audioFile looping:NO deferBuffering:false completionHandler:nil];

From what I understand from Apple documentation on using swift framework in Objective-C, I thought that the initWithFile: looping: deferBuffering: completionHandler: was the good translation in objective-C from the swift init call defined in AKAudioPlayer.swift in AudioKit framework:

public init(file: AKAudioFile,
                looping: Bool = false,
                deferBuffering: Bool = false,
                completionHandler: AKCallback? = nil) throws...

The AKAudioFile object instantiation causes neither warning nor error. But on instantiation of AKAudioPlayer, the compiler returns an error, saying no interface declares the selector initWithFile: looping: deferBuffering: completionHandler:

What am I doing wrong? Thanks for help

Upvotes: 2

Views: 1210

Answers (2)

Denis
Denis

Reputation: 795

AudioKit was just released as 4.0.1 to correct some bugs. So my question is now obsolete!

Upvotes: 2

Kamil.S
Kamil.S

Reputation: 5543

By cmd-clicking the AKAudioPlayer you can see the interface exposed to objective-c, the only available init is:

- (nonnull instancetype)init SWIFT_UNAVAILABLE;

Properties relevant to loading a file would be:

@property (nonatomic, readonly, strong) AKAudioFile * _Nonnull audioFile;
@property (nonatomic, readonly, copy) NSString * _Nonnull path; 

Since the 1st is read only I'd give a shot with the latter one. So you'd end up with:

@import AudioKit;

- (void)inSomeMethod {
    AKAudioPlayer *player = [[AKAudioplayer alloc] init];
    player.path = @"/myPath/To/audioFile";
}

Upvotes: 0

Related Questions