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

  • 相关阅读:
    SQL Serever学习16——索引,触发器,数据库维护
    微信WeUI基础
    SQL Serever学习15——进阶
    SQL Serever学习14——存储过程和触发器
    微信WeUI入门2
    微信WeUI入门
    数据库—索引
    数据库—四种存储引擎
    视图
    事务
  • 原文地址:https://www.cnblogs.com/8335IT/p/13633930.html
Copyright © 2011-2022 走看看