Post

Replies

Boosts

Views

Activity

Get AVAudioSequencer to notify completion
Hello,I have the following code to get an AVAudioSequencer playing a MIDI file: AVAudioEngine *engine; AVAudioUnitSampler *sampler; AVAudioSequencer *sequencer; engine = [[AVAudioEngine alloc] init]; sampler = [[AVAudioUnitSampler alloc] init]; [engine attachNode:sampler]; [engine connect:sampler to:engine.mainMixerNode format:nil]; NSURL *url = [NSBundle.mainBundle URLForResource:@"mysamples" withExtension:@"sf2"]; [sampler loadSoundBankInstrumentAtURL:url program:0 bankMSB:(UInt8)kAUSampler_DefaultMelodicBankMSB bankLSB:(UInt8)kAUSampler_DefaultBankLSB error:&err]; sequencer = [[AVAudioSequencer alloc] initWithAudioEngine:engine]; [engine startAndReturnError:&err]; [AVAudioSession.sharedInstance setCategory:AVAudioSessionCategoryPlayback error:&err]; [sequencer loadFromData:someMidiData options:AVMusicSequenceLoadSMF_PreserveTracks error:&err]; [sequencer startAndReturnError:&err];It is fairly straightforward code and it works.The point is that I need to be notified when the playback completes and I don't know how to achieve this.The best thing I have thought so far is polling the sequnecer's isPolling property.I know some objects can be connected to an AudioCompletionHandler, but I don't think it's the case of the sequencer, since it does not inherit from AVAudioNode.Any help is appreciated.
2
0
454
Apr ’20