简体   繁体   English

使用未声明的标识符'audioRouteChangeListenerCallback'

[英]use of undeclared identifier 'audioRouteChangeListenerCallback'

Trying to initialize audiosession so that app audio plays in background and shows remote control events to control audio when screen locks but getting error use of undeclared identifier 'audioRouteChangeListenerCallback' 尝试初始化音频会话,以使应用音频在后台播放并在屏幕锁定时显示遥控事件以控制音频,但错误使用了未声明的标识符'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];
}}

Any help will be really appreciated. 任何帮助将不胜感激。

Thanks 谢谢

You really have an undeclared identifier called audioRouteChangeListenerCallback. 您确实有一个未声明的标识符,称为audioRouteChangeListenerCallback。 This isn't a symbol that is defined in the CoreAudio framework AFAIK, however, some of Apple's sample code sources define it, eg MixerHost , in MixerHostAudio.m . 这不是CoreAudio框架AFAIK中定义的符号,但是,Apple的一些示例代码源对其进行了定义,例如MixerHostAudio.m中的MixerHostAudio.m

The comment in that source file is instructive: 该源文件中的注释具有指导意义:

// 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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM