1

アプリのオーディオがバックグラウンドで再生され、画面がロックされたときにオーディオを制御するリモート コントロール イベントが表示されるように audiosession を初期化しようとしていますが、宣言されていない識別子 'audioRouteChangeListenerCallback' の使用でエラーが発生します

- (void) setupAudioSession {

AVAudioSession *mySession = [AVAudioSession sharedInstance];

// Specify that this object is the delegate of the audio session, so that
//    this object's endInterruption method will be invoked when needed.
[mySession setDelegate: self];

// Assign the Playback category to the audio session.
NSError *audioSessionError = nil;
[mySession setCategory: AVAudioSessionCategoryPlayback
                 error: &audioSessionError];

if (audioSessionError != nil) {

    NSLog (@"Error setting audio session category.");
    return;
}

// Activate the audio session
[mySession setActive: YES
               error: &audioSessionError];

if (audioSessionError != nil) {

    NSLog (@"Error activating audio session during initial setup.");
    return;
}

// Increase the maximum frames per slice allows the mixer unit to accommodate the
//    larger slice size used when the screen is locked.
UInt32 maximumFramesPerSlice = 4096;

 AudioUnitSetProperty (
                               mixerUnit,
                               kAudioUnitProperty_MaximumFramesPerSlice,
                               kAudioUnitScope_Global,
                               0,
                               &maximumFramesPerSlice,
                               sizeof (maximumFramesPerSlice)
                               );

// Register the audio route change listener callback function with the audio session.
AudioSessionAddPropertyListener (
kAudioSessionProperty_AudioRouteChange,
audioRouteChangeListenerCallback, self );
 }

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
 }

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}

- (BOOL)canBecomeFirstResponder {
return YES;
}

- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
//if it is a remote control event handle it correctly
if (event.type == UIEventTypeRemoteControl) {
    if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) {

        [self playAction];

    }  else if (event.subtype == UIEventSubtypeRemoteControlPreviousTrack) {
        [self rewButtonPressed];

    } else if (event.subtype == UIEventSubtypeRemoteControlNextTrack)
        [self ffwButtonPressed:nil];
}}

どんな助けでも本当に感謝します。

ありがとう

4

1 に答える 1

0

実際には、audioRouteChangeListenerCallback という宣言されていない識別子があります。これは CoreAudio フレームワーク AFAIK で定義されているシンボルではありませんが、Apple のサンプル コード ソースの一部では、MixerHost などで定義されてますMixerHostAudio.m

そのソース ファイルのコメントは有益です。

// Audio session callback function for responding to audio route changes. If playing back audio and
//   the user unplugs a headset or headphones, or removes the device from a dock connector for hardware
//   that supports audio playback, this callback detects that and stops playback.
//
// Refer to AudioSessionPropertyListener in Audio Session Services Reference.
于 2013-05-14T18:31:50.637 に答える