# headset_detection_status **Repository Path**: super0086/headset_detection_status ## Basic Information - **Project Name**: headset_detection_status - **Description**: 耳机状态监听,包括有线耳机和蓝牙耳机。获取当前耳机状态,监听耳机并实时获取状态。 可以主动获取耳机状态,也可以动态实时监听耳机的状态。支持的耳机类型包括有线耳机、蓝牙耳机,同时支持ios和android平台。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2021-01-03 - **Last Updated**: 2023-08-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # headset_detection_status 耳机状态监听,包括有线耳机和蓝牙耳机。获取当前耳机状态,监听耳机并实时获取状态。 # 说明 可以主动获取耳机状态,也可以动态实时监听耳机的状态。支持的耳机类型包括有线耳机、蓝牙耳机,同时支持ios和android平台。 # Usage Sample usage ## Example 获取耳机状态 ```dart import 'package:headset_detection_status/headset_detect.dart'; final HeadsetDetect _headsetDetect = HeadsetDetect(); HeadsetState state = await _headsetDetect.checkHeadset(); if (state.wired == HeadsetStateEnum.CONNECTED) { //有线耳机已连接 } else if(state.wired == HeadsetStateEnum.DISCONNECTED) { //有线耳机已断开 } ``` 监听耳机状态 ```dart final HeadsetDetect _headsetDetect = HeadsetDetect(); StreamSubscription _subscription = _headsetDetect.onHeadsetStateChanged.listen((HeadsetState state) { if (state.bluetooth == HeadsetStateEnum.CONNECTED) { //蓝牙耳机已连接 } else if(state.bluetooth == HeadsetStateEnum.DISCONNECTED) { //蓝牙耳机已断开 } }); ```