zoukankan      html  css  js  c++  java
  • iOS 蓝牙耳机检测

    关于iOS 蓝牙耳机的摘掉,带上的检测:

    1 AVAudioSessioncategoryPlayAndRecord

    2 AVAudiosessionModeDefault

    3 kAudioSessionProperty_OverrideCategoryEnableBluetoothInput

    4  kAudioSessionProperty_OverrideCategoryDefaultToSpeaker

    5 AudioSessionAddpropertyListener(kAudioSessionProperty_AudioRouteChange,audioRouteChangeListenerCallback,null)

    6 回调实现:

    void audioRouteChangeListenerCallback (
    
    void                      *inUserData,
    
    AudioSessionPropertyID    inPropertyID,
    
    UInt32                    inPropertyValueSize,
    
    const void                *inPropertyValue
    
                                           ) {
    
    if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return;
    
    CFDictionaryRef routeChangeDictionary = (CFDictionaryRef)inPropertyValue;
    
    CFNumberRef routeChangeReasonRef =
    
        (CFNumberRef)CFDictionaryGetValue (routeChangeDictionary,
    
                              CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
    
    SInt32 routeChangeReason;
    
    CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
    
    if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable) {
    
    NSLog(@"拔掉耳机");
    
        } elseif (routeChangeReason == kAudioSessionRouteChangeReason_NewDeviceAvailable) {
    
    NSLog(@"插入耳机");
    
        } elseif (routeChangeReason == kAudioSessionRouteChangeReason_NoSuitableRouteForCategory) {
    
        }
    
    }

    代码来源:https://www.cnblogs.com/fangkuai/p/4241616.html

  • 相关阅读:
    Conda 中安装 Keras
    Clean Docker :
    Conservation Vs Non-conservation Forms of conservation Equations
    C语言之预处理命令
    const指针用法总结
    C语言中的小启发(陆续更新。。。)
    左值与右值
    计算的次序
    C语言中的符号重载
    C语言之switch语句详解
  • 原文地址:https://www.cnblogs.com/8335IT/p/13633930.html
Copyright © 2011-2022 走看看