1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Flutter audio_service does not start when the app is not in the foreground on iOS

Discussão em 'Mobile' iniciado por Stack, Novembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I've been building a Flutter app that needs to trigger an alarm while in the background.

    I am using audio_service in combination with just_audio (latest versions of both) but am only hearing the alarm if it is triggered when the app is in the foreground.

    My handler always recieves the callback to start playing, and no exceptions are thrown by the audio player.

    I've tried using the IsolatedAudioHandler class as explained in the FAQ and it behaves exactly the same way: sound is only heard when in the foreground.

    The alarm is triggered by GPS location updates when the user leaves a guard-zone.

    Any advice would be greatly appreciated.

    This is my handler code:

    class AudioPlayerHandler extends BaseAudioHandler {
    final _player = AudioPlayer();

    AudioPlayerHandler() {
    _player.setUrl("https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3");
    }

    @override
    Future<void> play() {
    try {
    print("****** play *******");
    return _player.play();
    } catch (e) {
    print(e);
    return Future.value(null);
    }
    }

    @override
    Future<void> pause() {
    return _player.pause();
    }
    }```

    Continue reading...

Compartilhe esta Página