Search code examples
iosfluttergoogle-chromesafari

flutter web safari ios no sound until user interaction detected


I am using livekit to implement audio/video in a flutter app, but on ios on safari and chrome there is no sound until a user interaction(with the DOM) is detected like granting microphone permission. Does someone know a way to detect user interaction without asking for permission or using the dart:html package?


Solution

  • The livekit team added new functionality after i opened an issue

    the workaround is this:

    EventsListener<RoomEvent> _listener
    Room room
    ...
    
    Future<bool?> showConfirmDialog() async{
      //here we show an alert dialog requesting permission
    }
    
    void _setUpListeners() => _listener
       
        ..on<AudioPlaybackStatusChanged>((event) async {
          if (!room.canPlaybackAudio) {
            print('Audio playback failed ..........');
            bool? yesno = await showConfirmDialog();
            if (yesno == true) {
              await room.startAudio();
            }
          }
        });