bluefireteam / audioplayers

A Flutter package to play multiple audio files simultaneously (Android/iOS/web/Linux/Windows/macOS)
https://pub.dartlang.org/packages/audioplayers
MIT License
2.01k stars 844 forks source link

onAudioPositionChanged stream is not fired in iOS, but works in Android #358

Closed a-v-ebrahimi closed 3 years ago

a-v-ebrahimi commented 4 years ago

I used code below from your example to update player position in my UI, it works on Android perfectly, but doesn't work on iOS (listener is never called) :

_positionSubscription =
        _audioPlayer.onAudioPositionChanged.listen((p) => setState(() {
              _position = p;
            }));
AnasMasri commented 4 years ago

I have the same issue, any update to this issue?

volgin commented 4 years ago

The same code works for me in iOs.

Try catching errors:

    _positionSubscription = _audioPlayer.onAudioPositionChanged
        .listen((_p) => _handlePosition(_p), onError: (_msg) {
      print(_msg);
    });
AnasMasri commented 4 years ago

I've already tried this, no errors are produced!

AnasMasri commented 4 years ago

After debugging from both sides (Dart platform channel API, Objective-C) code I just recognized that there is something wrong happening with the iOS platform channel events.

In AudioplayerPlugin.m line: 543 the following is getting called: [_channel_audioplayer invokeMethod:@"audio.onCurrentPosition" arguments:@{@"playerId": playerId, @"value": @(mseconds)}];

on every time interval but Dart method audio.onCurrentPosition isn't getting called! In fact, even platformCallHandler isn't getting called at all on any received event, thus I'm only receiving the updated status (which is changing in the setter according to some dart written logic and not from a received event from native code).

Any ideas?

AnasMasri commented 4 years ago

After more and more debugging, just realized that there is some conflict in my plugin registry, as I'm using

flutter_downloader dependency: https://pub.dev/packages/flutter_downloader

When I comment out the flutter downloader init method, everything works great.

The point is in order to use Flutter downloader plugin, you have to register the registrant callback like this: FlutterDownloaderPlugin.setPluginRegistrantCallback(registerPlugins) and as mentioned in the documentation:

In Flutter, in order to work in background isolate, plugins need to register with a special instance of FlutterEngine that serves for background execution only. Hence, all (and only) plugins that require background execution feature need to call registerWithRegistrar in this function.

But the method: optional static func setPluginRegistrantCallback(_ callback: @escaping FlutterPluginRegistrantCallback) in protocol FlutterPlugin : FlutterApplicationLifeCycleDelegate isn;t overriden which is causing an exception on app opening.

Any ideas to fix?

alexeypodolian commented 4 years ago

Any updates on this issue?

muarachmann commented 4 years ago

Hi @alexeypodolian this works fine for me

kiscsiri commented 4 years ago

I am experiencing the same issue @AnasMasri explained, but I don't have FlutterDownloader, rather, my application stops getting onPositionChanged event signals, when I start a background music with AudioService libary.

erickzanardo commented 3 years ago

Closing this due to reports of this being fixed on newer versions. Feel free to open a new issue in case of this still happening

18BG commented 1 year ago

Salut

18BG commented 1 year ago

Est ce que le onAudioPositionchanged marche à nos jours, c'est à dire en 2022, car depuis là je suis entrain de regarder un tuto et essayer de reproduire mais je remarque que ça ne marche pas

Gustl22 commented 1 year ago

@18BG

  1. Plz try to ask your questions in english
  2. Raise a new issue, with all the information asked in the issue template. Otherwise we cannot help.
  3. You most likely don't use the current version of Audioplayers. Try to upgrade it.