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

  • 相关阅读:
    array note
    前端开发规范
    java集合分类
    react native环境
    gulp
    关于如何在海量手机号中刷选出想要的手机号
    生成用户头像插件
    下拉加载
    阿里云人脸人体识别调试心得与备忘
    Sublime text3使用时有卡顿现象
  • 原文地址:https://www.cnblogs.com/8335IT/p/13633930.html
Copyright © 2011-2022 走看看