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

  • 相关阅读:
    file_get_contents高級用法
    php缓存技术常用函数
    php爬虫的两种思路
    jQuery判断文本框是否为空
    Asp.net 实现图片缩放 无水印(方法二)
    C# winform关于DataGridView的一些操作
    PHP判断访问者手机移动端还是PC端的函数
    本地图片显示在网页
    如何安装 Composer
    国内开源镜像站
  • 原文地址:https://www.cnblogs.com/8335IT/p/13633930.html
Copyright © 2011-2022 走看看