Skip to content

🎧 Flutter plugin to detect whether any headphones (wired or bluetooth) are connected to device.

License

Notifications You must be signed in to change notification settings

solid-software/flutter_audiomanager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flutter Audiomanager

Flutter plugin to detect whether any headphones (wired or bluetooth) are connected to device. It supports only Android at the moment. Work examples:

  • There are no connected headphones: Alt text

  • There are wired connected headphones: Alt text

  • There are Bluetooth connected headphones: Alt text

  • All types are connected: Alt text

Getting Started

Detect current connection state

To detect are there any connected headphones use following:

final HeadphonesDetector headphonesDetector = HeadphonesDetector();
HeadphonesConnectionState currentState = await headphonesDetector.headphonesState();

Use HeadphonesType to specify detector behavior:

final HeadphonesDetector headphonesDetector = HeadphonesDetector();
HeadphonesConnectionState currentWiredConnectionState = await headphonesDetector.headphonesState(headphonesType: HeadphonesType.wired);
HeadphonesConnectionState currentBluetoothConnectionState = await headphonesDetector.headphonesState(headphonesType: HeadphonesType.bluetooth);

Using Streams

To receive changes in connection state for wired headphones you can use following:

final HeadphonesDetector headphonesDetector = HeadphonesDetector();
headphonesDetector.wiredHeadphonesConnectionState.listen(print);

You can receive changes for Bluetooth headphones as well:

final HeadphonesDetector headphonesDetector = HeadphonesDetector();
headphonesDetector.bluetoothHeadphonesConnectionState.listen(print);

Current issues

Current issues list is here.
Found a bug? Open the issue.

About

🎧 Flutter plugin to detect whether any headphones (wired or bluetooth) are connected to device.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages