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 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 restoreDefaultOutput() async { if (!Platform.isAndroid && !Platform.isIOS) return; try { await _channel.invokeMethod('restoreDefaultOutput'); } on PlatformException catch (e) { print('[AudioRoutingChannel] restoreDefaultOutput failed: $e'); } } }