检查当前或以前的音频类别iOS

时间:2014-04-15 03:06:50

标签: ios core-audio avaudiosession

我有一个包含多个AudioSession和他们自己的aduioRouteChangeCallback的应用程序。我需要一种方法来查看当前或以前的音频类别是什么,以便向用户显示正确的消息。

有谁知道这样做的方法?从我在网上看到的到目前为止,我的希望并不高,这可以从我在网上找到的内容中实现。任何帮助都非常感激,因为我在最后期限前工作。

以下是我的audioRouteChangeCallback之一的示例

- (void) audioRouteChangeListener: (NSNotification*)notification {
    // Initiallize dictionary with notification and grab route change reason
    NSDictionary *interuptionDict = notification.userInfo;
    NSInteger routeChangeReason = [[interuptionDictvalueForKey:
        AVAudioSessionRouteChangeReasonKey] integerValue];

    NSLog(@"MADE IT: sensorAudioRouteChageListener");

    switch (routeChangeReason) {
        // Sensor inserted
        case AVAudioSessionRouteChangeReasonNewDeviceAvailable:
            // Start IO communication
            [self startCollecting];


            NSLog(@"Sensor INSERTED");
            break;

        // Sensor removed
        case AVAudioSessionRouteChangeReasonOldDeviceUnavailable:
            // Stop IO audio unit
            [self stopCollecting];


            NSLog(@"Sensor REMOVED");
            break;

        // Category changed from PlayAndRecord
        case AVAudioSessionRouteChangeReasonCategoryChange:
            // Stop IO audio unit
            [self stopCollecting];

            NSLog(@"Category CHANGED");
            break;

        default:
            NSLog(@"Blowing it in- audioRouteChangeListener with route change reason: %ld",
                (long)routeChangeReason);
            break;
    }
}

会话在对象init函数

中初始化
- (id) init {
    self = [super init];
    if (!self) return nil;

    // Set up AVAudioSession
    self->noiseAudioSession = [AVAudioSession sharedInstance];
    BOOL success;
    NSError *error;
    success = [self->noiseAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
    if (!success) NSLog(@"ERROR initNoiseRecorder: AVAudioSession failed overrideOutputAudio- %@", error);
    success = [self->noiseAudioSession setActive:YES error:&error];
    if (!success) NSLog(@"ERROR initNoiseRecorder: AVAudioSession failed activating- %@", error);

    return self;
}

0 个答案:

没有答案