34 lines
1.3 KiB
Dart
34 lines
1.3 KiB
Dart
import 'dart:io';
|
|
import 'package:flutter/services.dart';
|
|
|
|
/// Channel Dart vers le plugin natif AudioRoutingPlugin.
|
|
/// Permet de forcer la sortie audio sur les lunettes (A2DP Bluetooth)
|
|
/// au lieu du haut-parleur téléphone.
|
|
class AudioRoutingChannel {
|
|
static const MethodChannel _channel =
|
|
MethodChannel('be.unov.mymuseum/audio_routing');
|
|
|
|
/// Force la sortie audio vers le device Bluetooth connecté (lunettes).
|
|
/// iOS : AVAudioSession .playAndRecord + .allowBluetoothA2DP + .allowBluetoothHFP
|
|
/// Android : AudioManager setCommunicationDevice(A2DP)
|
|
static Future<void> enableBluetoothOutput() async {
|
|
if (!Platform.isAndroid && !Platform.isIOS) return;
|
|
try {
|
|
await _channel.invokeMethod('enableBluetoothOutput');
|
|
} on PlatformException catch (e) {
|
|
// Dégradation gracieuse — le son jouera sur le haut-parleur par défaut
|
|
print('[AudioRoutingChannel] enableBluetoothOutput failed: $e');
|
|
}
|
|
}
|
|
|
|
/// Restaure la sortie audio par défaut (haut-parleur téléphone).
|
|
static Future<void> restoreDefaultOutput() async {
|
|
if (!Platform.isAndroid && !Platform.isIOS) return;
|
|
try {
|
|
await _channel.invokeMethod('restoreDefaultOutput');
|
|
} on PlatformException catch (e) {
|
|
print('[AudioRoutingChannel] restoreDefaultOutput failed: $e');
|
|
}
|
|
}
|
|
}
|