搜尋套件、儲存庫與 APP 分類

套件詳情v3.1.0

flutter_headset_detector

用於耳機事件的 Flutter 插件。偵測耳機是否已插入和拔出。取得目前耳機狀態。

AndroidiOS
近 30 天下載
1030
喜歡數
5
Pub 分數
150

安裝套件

flutter pub add flutter_headset_detector

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 插件,可在 Android 和 iOS 裝置上偵測耳機連接事件。它允許應用程式在耳機插入或拔除時做出回應,並提供目前的耳機狀態。非常適合需要即時了解音訊輸出變更的音訊應用。此插件與 Flutter 的事件系統無縫整合,支援兩個平台且設定簡單。開發者可利用它根據耳機存在性來調整音訊路由或 UI 行為,進而提升使用者體驗。

適用情境

  • 音頻應用增強
  • 即時音訊路由
  • 使用者介面適應
  • 設備狀態監控
  • 媒體播放控制

主要特色

  • 檢測耳機插入/拔出事件
  • 提供目前耳機狀態
  • 跨平台(Android & iOS)
  • 簡單的事件驅動式 API
  • 輕量且可靠

適合對象

  • 音頻應用
  • 媒體播放器
  • 可存取性工具
  • 需要硬體反饋的行動應用程式
  • 開發響應式音訊介面的開發者

使用建議

  • 需要平台特定權限
  • 僅限頭戴裝置檢測
  • 不支援藍牙耳機
  • 依賴於原生設備功能
  • 可能需要在實體裝置上進行測試

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Flutter Headset Detector Plugin

A Flutter plugin to get a headset event.

This is a clone of headset_connection_event, but seperated wired and wireless event.

Current Status

Platform Physical Headset Bluetooth
iOS ✅ ✅
Android ✅ ✅

Usage

To use this plugin, add flutter_headset_detector as a dependency in your pubspec.yaml file.

Example
// Import package
import 'package:flutter_headset_detector/flutter_headset_detector.dart';

// Instantiate it
final headsetDetector = HeadsetDetector();
Map<HeadsetType, HeadsetState> headsetState = {
  HeadsetType.WIRED: HeadsetState.DISCONNECTED,
  HeadsetType.WIRELESS: HeadsetState.DISCONNECTED,
};

// if headset is plugged
headsetDetector.getCurrentState.then((_val){
  headsetState = _val;
  setState(() {
  });
});

// Detect the moment headset is plugged or unplugged with a Listener
headsetDetector.setListener((_val) {
  switch (_val) {
    case HeadsetChangedEvent.WIRED_CONNECTED:
      headsetState[HeadsetType.WIRED] = HeadsetState.CONNECTED;
      break;
    case HeadsetChangedEvent.WIRED_DISCONNECTED:
      headsetState[HeadsetType.WIRED] = HeadsetState.DISCONNECTED;
      break;
    case HeadsetChangedEvent.WIRELESS_CONNECTED:
      headsetState[HeadsetType.WIRELESS] = HeadsetState.CONNECTED;
      break;
    case HeadsetChangedEvent.WIRELESS_DISCONNECTED:
      headsetState[HeadsetType.WIRELESS] = HeadsetState.DISCONNECTED;
      break;
  }
  setState(() {
  });
});

// Remove the Listener
headsetDetector.removeListener();

Screenshot

  • There are no connected headphones:

  • There are wired connected headphones:

  • There are Bluetooth connected headphones:

  • All types are connected:

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。