Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flutter: Fatal Error: Callback lookup failed! #344

Closed
gustavobrian opened this issue Dec 2, 2019 · 73 comments
Closed

flutter: Fatal Error: Callback lookup failed! #344

gustavobrian opened this issue Dec 2, 2019 · 73 comments

Comments

@gustavobrian
Copy link

console log print everytime Fatal Error: Callback lookup failed!
flutter stable channel
version audioplayers: ^0.13.3

Thanks!

@imaNNeo
Copy link

imaNNeo commented Dec 3, 2019

I have this issue too

@JonathanIvyCR
Copy link

I'm also getting this error. It doesn't seem to cause any problem and the audio plays.

@pobrejuanito
Copy link
Contributor

For me it happens when audio completes.

@JesseScott
Copy link

think this is fixed in #332

@luanpotter
Copy link
Member

merged #332, released on 0.13.5, thanks @JesseScott

@volgin
Copy link
Contributor

volgin commented Jan 27, 2020

I see this error in 0.14.0 version.

I call setNotification(), and the correct information appears in the Command Center and Notifications on iPhone. Any attempt to click on a pause/play button in the Command Center or Notifications causes this message:
Fatal Error: Callback lookup failed!

Interestingly, onNotificationPlayerStateChanged() is called with the correct state despite this error message. When a file is playing from a URL, the app continues to work, but with a local file this error crashes the app.

@AatiqUrRehman
Copy link

AatiqUrRehman commented Mar 24, 2020

any solution yet? getting same error

@tko2100
Copy link

tko2100 commented Mar 28, 2020

Same here. Anyone have a solution?

@nohli
Copy link
Contributor

nohli commented Mar 29, 2020

My app works fine (is playing all local sounds), but shows this error in console shortly after every sound.

@DenisPushkarev
Copy link

Same here,
getting
flutter: onNotificationPlayerStateChanged!
flutter: Fatal Error: Callback lookup failed!
Seems like audioPlayer.onPlayerStateChanged.listen((state) callback doesn't work.

@handofthecode
Copy link

Same issue here. latest version.

@lukepighetti
Copy link

lukepighetti commented Apr 5, 2020

Same issue here, latest version. All I'm doing is playing a sound. It happens when it completes.

import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:ptp/config.dart';

class SoundService {
  SoundService() {
    player.loadAll(AppConfig.toneOptions.values.withoutAssetOnFront);
  }

  static final player = AudioCache();

  void play(String path) async {
    player.play(path.withoutAssetOnFront, mode: PlayerMode.LOW_LATENCY);
  }
}

extension on Iterable<String> {
  List<String> get withoutAssetOnFront =>
      this.map((e) => e.withoutAssetOnFront).toList();
}

extension on String {
  String get withoutAssetOnFront => this.replaceFirst("assets/", "");
}
flutter: Fatal Error: Callback lookup failed!
flutter: Fatal Error: Callback lookup failed!
flutter: Fatal Error: Callback lookup failed!
flutter: Fatal Error: Callback lookup failed!
flutter: Fatal Error: Callback lookup failed!
flutter: Fatal Error: Callback lookup failed!
flutter: Fatal Error: Callback lookup failed!
flutter: Fatal Error: Callback lookup failed!
flutter: Fatal Error: Callback lookup failed!

@lukepighetti
Copy link

@luanpotter please reopen

@chancelorb
Copy link

Same issue, I am using the latest version.

@alanmeier
Copy link

It also happens using the example on GitHub as well

@mirkopoloni
Copy link

I do also get the same error.

Version
0.15.0

Where
iPad 7th generation - iOS Simulator

When
When a file (from local assets) finishes playing.

More infos

  • I'm using AudioCache.
  • The error occurs with both play and loop

Error log
The error I get is:

Exception has occurred.
NoSuchMethodError (NoSuchMethodError: The method 'call' was called on null.
Receiver: null
Tried calling: call(Instance of 'AudioPlayerState'))

From
_backgroundCallbackDispatcher.<anonymous closure> (audioplayers-0.15.0/lib/audioplayers.dart:116)

if (call.method == 'audio.onNotificationBackgroundPlayerStateChanged') {
      onAudioChangeBackgroundEvent ??= _performCallbackLookup();
      final String playerState = callArgs['value'];
      if (playerState == 'playing') {
        onAudioChangeBackgroundEvent(AudioPlayerState.PLAYING);
      } else if (playerState == 'paused') {
        onAudioChangeBackgroundEvent(AudioPlayerState.PAUSED);
      } else if (playerState == 'completed') {
        onAudioChangeBackgroundEvent(AudioPlayerState.COMPLETED);
      }
    }

onAudioChangeBackgroundEvent is null.

@orestesgaolin
Copy link

Yup, getting the same error as above

@ricnaaru
Copy link

ricnaaru commented Apr 9, 2020

i've solved the issue by calling the "monitorNotificationStateChanges" method and passing the static function into it

@nohli
Copy link
Contributor

nohli commented Apr 9, 2020

i've solved the issue by calling the "monitorNotificationStateChanges" method and passing the static function into it

Could you please post the code of that fix, or even submit a pull request? 😊

@ricnaaru
Copy link

just add this script

audioPlayer.monitorNotificationStateChanges(monitorNotificationStateHandler);

and dont forget to add the handler method to be static / top level function (outside of your class), so it could be accessed from the headless state

static method

static void x(AudioPlayerState value) {
    print("state => $value");
  }

top-level function

void x(AudioPlayerState value) {
    print("state => $value");
}
  
class Test extends StatefulWidget{
    ...
}

Please note to match the return type and the argument type, otherwise it won't work

@nimisis
Copy link
Contributor

nimisis commented Apr 17, 2020

just add this script

audioPlayer.monitorNotificationStateChanges(monitorNotificationStateHandler);

This causes a problem in Android for me:

MissingPluginException(No implementation found for method monitorNotificationStateChanges on channel xyz.luan/audioplayers)

@nohli
Copy link
Contributor

nohli commented Apr 17, 2020

just add this script
audioPlayer.monitorNotificationStateChanges(monitorNotificationStateHandler);

This causes a problem in Android for me:

MissingPluginException(No implementation found for method monitorNotificationStateChanges on channel xyz.luan/audioplayers)

You can add:

import 'dart:io';

if (Platform.isIOS) ...

@vinnytwice
Copy link

@nohli Hi I'm another one facing this error..
I'm using AudioCache() to play local files And I tried your fix with this code:

 void audioPlayerHandler(AudioPlayerState value) {
    print("state => $value");
  }

  @override
  Widget build(BuildContext context) {
    AudioCache cache = new AudioCache();
    AudioPlayer audioPlayer = new AudioPlayer();
    Platform.isIOS
        ? audioPlayer.monitorNotificationStateChanges(audioPlayerHandler)
        // ignore: unnecessary_statements
        : () {};

but I now get
this periodically:

[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'toRawHandle' was called on null.
Receiver: null
Tried calling: toRawHandle()
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1 AudioPlayer.monitorNotificationStateChanges (package:audioplayers/audioplayers.dart:354:44)
#2 _MapScreenState.build (package:fixit_cloud_biking/Screens/map_screen.dart:221:23)
#3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4334:27)
#4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4223:15)
#5 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#6 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2432:33)
#7 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:773:20)
#8 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
#9 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
#10 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)
#11 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:957:5)
#12 _rootRun (dart:async/zone.dart:1126:13)
#13 _CustomZone.run (dart:async/zone.dart:1023:19)
#14 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
#15 _invoke (dart:ui/hooks.dart:259:10)
#16 _drawFrame (dart:ui/hooks.dart:217:3)

not sure of what I'm doing dough..is this what you meant? I had to create an instance of AudioPlayer() as your fix was about it and not about AudioCache().
Is there a different fix for it?
Thank you very much

@nohli
Copy link
Contributor

nohli commented Apr 27, 2020

@vinnytwice I can give you my code which is working:

// during first app start i once call:
// if (Platform.isIOS) audioPlayerStateMonitor();

void audioPlayerStateMonitor() =>
    _audioPlayer.monitorNotificationStateChanges(_audioPlayerStateUpdate);

void _audioPlayerStateUpdate(AudioPlayerState state) => state;

AudioPlayer _audioPlayer = AudioPlayer(mode: PlayerMode.LOW_LATENCY);

AudioCache _player = AudioCache(fixedPlayer: _audioPlayer);

// this could be written more verbose and easier to read
Future<void> sound(String sound) async => _audioPlayerStateUpdate((await _player.play(sound)).state);

@miguelpruivo
Copy link

Same issue while using AudioCache only. This probably should be reopened.

@ghost
Copy link

ghost commented May 5, 2020

Tried will all the methods still the issue persists.
I am trying to run on iPhone 11 pro max simulator. Help !!

@nohli
Copy link
Contributor

nohli commented May 5, 2020

@krishnatandon1208 can you share your code?

@xni06
Copy link

xni06 commented Jul 23, 2020

Any updates on this? This is a huge problem.

Did you try the solutions above? They worked for me. This is what I'm using:

import 'dart:io';

import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';

class Audio {
  static bool mute = false;

  AudioCache _audioCache;
  AudioPlayer _audioPlayer;

  Audio() {
    AudioPlayer.logEnabled = false;
    _audioPlayer = AudioPlayer(mode: PlayerMode.MEDIA_PLAYER);
    _audioCache = AudioCache(prefix: 'sounds/', fixedPlayer: _audioPlayer);
    _fixCallbackLookupFailedIssue();
  }

  // https://github.com/luanpotter/audioplayers/issues/344
  void _fixCallbackLookupFailedIssue() {
    if (Platform.isIOS) {
      _audioPlayer
          .monitorNotificationStateChanges(_audioPlayerStateChangeHandler);
    }
  }

  void start(String filename) {
    if (!mute) _audioCache.play(filename);
  }

  void loop(String filename) {
    if (!mute) _audioCache.loop(filename);
  }

  void stop() => _audioPlayer.stop();

  Future<void> dispose() async {
    await _audioPlayer.pause();
    await _audioPlayer.dispose();
  }
}

void _audioPlayerStateChangeHandler(AudioPlayerState state) => null;

@pawansgithub
Copy link

pawansgithub commented Jul 28, 2020

Here is the solution:
click on pubspec.yaml file and change the audioplayers version to audioplayers: ^0.10.0 and click pubset
then 0.10.0 version will be download to External Libraries.

Screenshot 2020-07-28 at 11 30 49 AM

Now the problem will sloved.....!!!

Screenshot 2020-07-28 at 11 30 04 AM

@xni06
Copy link

xni06 commented Jul 28, 2020

Here is the solution:
click on pubspec.yaml file and change the audioplayers version to audioplayers: ^0.10.0 and click pubset
then 0.10.0 version will be download to External Libraries.

Screenshot 2020-07-28 at 11 30 49 AM

Now the problem will sloved.....!!!

Reverting back to a release that was made 18 months ago and is 17 releases behind the current release? :-/

Why not use one of the above solutions along with the current release such as #344 (comment) ?

@pawansgithub
Copy link

Here is the solution:
click on pubspec.yaml file and change the audioplayers version to audioplayers: ^0.10.0 and click pubset
then 0.10.0 version will be download to External Libraries.
Screenshot 2020-07-28 at 11 30 49 AM
Now the problem will sloved.....!!!

Reverting back to a release that was made 18 months ago and is 17 releases behind the current release? :-/

Why not use one of the above solutions along with the current release such as #344 (comment) ?

I appreciate your code but for the beginners enough thing to get rid of errors in #terminal

@LugonjaAleksandar
Copy link

Here is the solution:
click on pubspec.yaml file and change the audioplayers version to audioplayers: ^0.10.0 and click pubset
then 0.10.0 version will be download to External Libraries.
Screenshot 2020-07-28 at 11 30 49 AM
Now the problem will sloved.....!!!

Reverting back to a release that was made 18 months ago and is 17 releases behind the current release? :-/
Why not use one of the above solutions along with the current release such as #344 (comment) ?

I appreciate your code but for the beginners enough thing to get rid of errors in #terminal

By downgrading 10 versions of this plugin, you just introduced at least 10 new errors to the system because all those releases in the mean time were bug fixes...it is fine enough if you get a warning in the console about this, but something completely different if you get real errors if you discard 8 months of code development from library maintainers. Be careful :)

@pawansgithub
Copy link

pawansgithub commented Jul 28, 2020

Here is the solution:
click on pubspec.yaml file and change the audioplayers version to audioplayers: ^0.10.0 and click pubset
then 0.10.0 version will be download to External Libraries.
Screenshot 2020-07-28 at 11 30 49 AM
Now the problem will sloved.....!!!

Reverting back to a release that was made 18 months ago and is 17 releases behind the current release? :-/
Why not use one of the above solutions along with the current release such as #344 (comment) ?

I appreciate your code but for the beginners enough thing to get rid of errors in #terminal

By downgrading 10 versions of this plugin, you just introduced at least 10 new errors to the system because all those releases in the mean time were bug fixes...it is fine enough if you get a warning in the console about this, but something completely different if you get real errors if you discard 8 months of code development from library maintainers. Be careful :)

then you should wait for the new release....hope they fix the problem regarding this issue.
just i tried my level best for the error free in the terminal and application is running fine...!!!!

@erickzanardo
Copy link
Member

Folks can someone confirm if this is still happening, and if so, can someone provide a simple code that reproduces this problem? I may try to take a look on this...

@pawansgithub
Copy link

Folks can someone confirm if this is still happening, and if so, can someone provide a simple code that reproduces this problem? I may try to take a look on this...

yes it is repeating same problem because of new update...!

@xni06
Copy link

xni06 commented Jul 28, 2020

Folks can someone confirm if this is still happening, and if so, can someone provide a simple code that reproduces this problem? I may try to take a look on this...

I am using the latest release and do not have the problem when using the suggested solution as per #344 (comment)

@ventr1x
Copy link

ventr1x commented Aug 12, 2020

How is this closed and considered fixed?

So we need to check for platform (because Android would crash with the "solution").
Fix this on every app with boilerplate code because the plugin does not simply check if a callback function is present.
Let every new user figure out by themselves where this error is coming from and how to find the fix buried in github.

Good work!

Not sure what test someone needs to reproduce.
I get that error on newest version on every .play() call. While AudioCache itself does not even expose any callback(?), so the fix does not apply.

Simple small service:

import 'dart:core';
import 'package:audioplayers/audio_cache.dart';

class Audio {
  final player = AudioCache();

  static final Audio _singleton = Audio._internal();

  factory Audio() {
    return _singleton;
  }

  Audio._internal();

  play(String audioFile) {
    player.play(audioFile);
  }
}

Even with the fix put onto Audioplayer (which I'm not using in my small example), the error still persists:

import 'dart:core';
import 'dart:io';
import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';

class Audio {
  AudioPlayer _audioPlayer;
  AudioCache _player;

  static final Audio _singleton = Audio._internal();

  factory Audio() {
    return _singleton;
  }

  Audio._internal() {
    _player = AudioCache();
    _audioPlayer = AudioPlayer();
    _fixCallbackLookupFailedIssue();
  }

  play(String audioFile) {
    _player.play(audioFile);
  }

  void _fixCallbackLookupFailedIssue() {
    if (Platform.isIOS) {
      _audioPlayer.monitorNotificationStateChanges(_audioPlayerStateChangeHandler);
    }
  }

  void _audioPlayerStateChangeHandler(AudioPlayerState state) => null;
}

Adding the fix (when using audioplayer instead of audiocache) also throws this error about 80% of the time (mentioned here and ignored...):

[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'toRawHandle' was called on null.
Receiver: null
Tried calling: toRawHandle()
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1      AudioPlayer.monitorNotificationStateChanges (package:audioplayers/audioplayers.dart:354:44)
#2      Audio._fixCallbackLookupFailedIssue (package:x/utils/audio.util.dart:32:20)
#3      new Audio._internal (package:x/utils/audio.util.dart:20:5)
#4      Audio._singleton (package:x/utils/audio.util.dart:11:41)
#5      Audio._singleton (package:x/utils/audio.util.dart:11:22)
#6      new Audio (package:x/utils/audio.util.dart:14:12)
#7      _ClickableState._onTap (package:x/widgets/clickable.dart:36:5)
#8      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#9      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
#10     BaseTapGestureRecognizer._checkUp <…>

@erickzanardo
Copy link
Member

How is this closed and considered fixed?

So we need to check for platform (because Android would crash with the "solution").
Fix this on every app with boilerplate code because the plugin does not simply check if a callback function is present.
Let every new user figure out by themselves where this error is coming from and how to find the fix buried in github.

Good work!

Not sure what test someone needs to reproduce.
I get that error on newest version on every .play() call. While AudioCache itself does not even expose any callback(?), so the fix does not apply.

Simple small service:

import 'dart:core';
import 'package:audioplayers/audio_cache.dart';

class Audio {
  final player = AudioCache();

  static final Audio _singleton = Audio._internal();

  factory Audio() {
    return _singleton;
  }

  Audio._internal();

  play(String audioFile) {
    player.play(audioFile);
  }
}

Even with the fix put onto Audioplayer (which I'm not using in my small example), the error still persists:

import 'dart:core';
import 'dart:io';
import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';

class Audio {
  AudioPlayer _audioPlayer;
  AudioCache _player;

  static final Audio _singleton = Audio._internal();

  factory Audio() {
    return _singleton;
  }

  Audio._internal() {
    _player = AudioCache();
    _audioPlayer = AudioPlayer();
    _fixCallbackLookupFailedIssue();
  }

  play(String audioFile) {
    _player.play(audioFile);
  }

  void _fixCallbackLookupFailedIssue() {
    if (Platform.isIOS) {
      _audioPlayer.monitorNotificationStateChanges(_audioPlayerStateChangeHandler);
    }
  }

  void _audioPlayerStateChangeHandler(AudioPlayerState state) => null;
}

Adding the fix (when using audioplayer instead of audiocache) also throws this error about 80% of the time (mentioned here and ignored...):

[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'toRawHandle' was called on null.
Receiver: null
Tried calling: toRawHandle()
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1      AudioPlayer.monitorNotificationStateChanges (package:audioplayers/audioplayers.dart:354:44)
#2      Audio._fixCallbackLookupFailedIssue (package:x/utils/audio.util.dart:32:20)
#3      new Audio._internal (package:x/utils/audio.util.dart:20:5)
#4      Audio._singleton (package:x/utils/audio.util.dart:11:41)
#5      Audio._singleton (package:x/utils/audio.util.dart:11:22)
#6      new Audio (package:x/utils/audio.util.dart:14:12)
#7      _ClickableState._onTap (package:x/widgets/clickable.dart:36:5)
#8      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#9      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
#10     BaseTapGestureRecognizer._checkUp <…>

This isn't closed, the issue is still open 🤔

@xni06
Copy link

xni06 commented Aug 12, 2020

How is this closed and considered fixed?

So we need to check for platform (because Android would crash with the "solution").
Fix this on every app with boilerplate code because the plugin does not simply check if a callback function is present.
Let every new user figure out by themselves where this error is coming from and how to find the fix buried in github.

Good work!

Not sure what test someone needs to reproduce.
I get that error on newest version on every .play() call. While AudioCache itself does not even expose any callback(?), so the fix does not apply.

Simple small service:

import 'dart:core';
import 'package:audioplayers/audio_cache.dart';

class Audio {
  final player = AudioCache();

  static final Audio _singleton = Audio._internal();

  factory Audio() {
    return _singleton;
  }

  Audio._internal();

  play(String audioFile) {
    player.play(audioFile);
  }
}

Even with the fix put onto Audioplayer (which I'm not using in my small example), the error still persists:

import 'dart:core';
import 'dart:io';
import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';

class Audio {
  AudioPlayer _audioPlayer;
  AudioCache _player;

  static final Audio _singleton = Audio._internal();

  factory Audio() {
    return _singleton;
  }

  Audio._internal() {
    _player = AudioCache();
    _audioPlayer = AudioPlayer();
    _fixCallbackLookupFailedIssue();
  }

  play(String audioFile) {
    _player.play(audioFile);
  }

  void _fixCallbackLookupFailedIssue() {
    if (Platform.isIOS) {
      _audioPlayer.monitorNotificationStateChanges(_audioPlayerStateChangeHandler);
    }
  }

  void _audioPlayerStateChangeHandler(AudioPlayerState state) => null;
}

Adding the fix (when using audioplayer instead of audiocache) also throws this error about 80% of the time (mentioned here and ignored...):

[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'toRawHandle' was called on null.
Receiver: null
Tried calling: toRawHandle()
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1      AudioPlayer.monitorNotificationStateChanges (package:audioplayers/audioplayers.dart:354:44)
#2      Audio._fixCallbackLookupFailedIssue (package:x/utils/audio.util.dart:32:20)
#3      new Audio._internal (package:x/utils/audio.util.dart:20:5)
#4      Audio._singleton (package:x/utils/audio.util.dart:11:41)
#5      Audio._singleton (package:x/utils/audio.util.dart:11:22)
#6      new Audio (package:x/utils/audio.util.dart:14:12)
#7      _ClickableState._onTap (package:x/widgets/clickable.dart:36:5)
#8      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#9      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
#10     BaseTapGestureRecognizer._checkUp <…>

From a cursory glance between your code and the workaround, I can see that you're not setting the fixedPlayer when creating the AudioCache...

_audioCache = AudioCache(prefix: 'sounds/', fixedPlayer: _audioPlayer);

@chornbe
Copy link

chornbe commented Aug 12, 2020 via email

@ventr1x
Copy link

ventr1x commented Aug 12, 2020

From a cursory glance between your code and the workaround, I can see that you're not setting the fixedPlayer when creating the AudioCache...

You're right, but it doesn't change much as it then runs into the toRawHandle exception as mentioned.

@erickzanardo
Copy link
Member

Folks can someone confirm if this is still happening, and if so, can someone provide a simple code that reproduces this problem? I may try to take a look on this...

Quoting my own message, if someone could provide a simple code that reproduce this, I could try giving a look, I have tried reproducing this on our example app and I am not been able to see this problem happening.

@xni06
Copy link

xni06 commented Aug 12, 2020

Folks can someone confirm if this is still happening, and if so, can someone provide a simple code that reproduces this problem? I may try to take a look on this...

Quoting my own message, if someone could provide a simple code that reproduce this, I could try giving a look, I have tried reproducing this on our example app and I am not been able to see this problem happening.

Better still, a full repo.

@ventr1x
Copy link

ventr1x commented Aug 12, 2020

Didn't I do that?

There is no error being thrown in the app itself but the log bubbles up. So it's annoying, but doesn't kill the app itself.
The other exception though is killing the app.

@xni06
Copy link

xni06 commented Aug 12, 2020

Please provide a working Flutter repo that we can clone so that we reproduce the error along with flutter doctor output and the device that you are testing against - thanks.

@m-j-g
Copy link

m-j-g commented Aug 20, 2020

I'm getting the same error using AudioCache.play()

flutter: Fatal Error: Callback lookup failed!

@xni06
Copy link

xni06 commented Aug 20, 2020

I'm getting the same error using AudioCache.play()

flutter: Fatal Error: Callback lookup failed!

#344 (comment)

@jb-thery
Copy link

jb-thery commented Sep 11, 2020

Hi,

@xni06 I' have the same error using AudioCache.play() with audioplayers: 0.16.1.

flutter: Fatal Error: Callback lookup failed!

Repo for bug reproduction :
https://github.com/jbty/flutter_xylophone

Device tested :
Simulator iOS 13.7 Iphone 11

Flutter doctor output :

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.20.3, on Mac OS X 10.15.6 19G2021, locale fr-FR)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.7)
[✓] Android Studio (version 4.0)
[✓] Connected device (1 available)

• No issues found!

Have a nice day

@xni06
Copy link

xni06 commented Sep 11, 2020

@xni06 I' have the same error using AudioCache.play() with audioplayers: 0.16.1.

flutter: Fatal Error: Callback lookup failed!

Repo for bug reproduction :
https://github.com/jbty/flutter_xylophone

Device tested :
Simulator iOS 13.7 Iphone 11

Flutter doctor output :

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.20.3, on Mac OS X 10.15.6 19G2021, locale fr-FR)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.7)
[✓] Android Studio (version 4.0)
[✓] Connected device (1 available)

• No issues found!

Have a nice day

Thanks for the repo - perfect. Here are the steps that I took a few moments ago...

  1. Cloned your repo
  2. Launched an iOS 13.7 Iphone 11 simulator
  3. flutter pub get then flutter run
  4. I was able to replicate the problem i.e. flutter: Fatal Error: Callback lookup failed!
  5. I applied the fix as per flutter: Fatal Error: Callback lookup failed! #344 (comment)
  6. Hit Control-R and... it worked

I note that your code did not have the suggested fix - did you try it before posting?

@jb-thery
Copy link

@xni06 Your temporary fix work for me:) I hope this bug will'be fixed for the last version of this awesome package 🙂

@denizdogan
Copy link

@xni06 Maybe that works for AudioPlayer, but AudioCache (which is required for using assets) doesn't have monitorNotificationStateChanges.

Just so that everyone is clear on this, this doesn't really crash anything, it just prints a message.

@xni06
Copy link

xni06 commented Sep 13, 2020

@denizdogan

@xni06 Maybe that works for AudioPlayer, but AudioCache (which is required for using assets) doesn't have monitorNotificationStateChanges.

  1. Create an AudioPlayer
  2. Create an AudioCache and inject the AudioPlayer into it via the constructor
  3. Apply the fix i.e. call monitorNotificationStateChanges on the injected AudioPlayer
  AudioCache _audioCache;
  AudioPlayer _audioPlayer;

  Audio() {
    AudioPlayer.logEnabled = false;
    _audioPlayer = AudioPlayer(mode: PlayerMode.MEDIA_PLAYER);
    _audioCache = AudioCache(prefix: 'sounds/', fixedPlayer: _audioPlayer);
    _fixCallbackLookupFailedIssue();
  }

  // https://github.com/luanpotter/audioplayers/issues/344
  void _fixCallbackLookupFailedIssue() {
    if (Platform.isIOS) {
      _audioPlayer
          .monitorNotificationStateChanges(_audioPlayerStateChangeHandler);
    }
  }

thlvu added a commit to thlvu/xylophone-flutter that referenced this issue Sep 15, 2020
@blueflamer
Copy link

Any updates on this? This is a huge problem.

Did you try the solutions above? They worked for me. This is what I'm using:

import 'dart:io';

import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';

class Audio {
  static bool mute = false;

  AudioCache _audioCache;
  AudioPlayer _audioPlayer;

  Audio() {
    AudioPlayer.logEnabled = false;
    _audioPlayer = AudioPlayer(mode: PlayerMode.MEDIA_PLAYER);
    _audioCache = AudioCache(prefix: 'sounds/', fixedPlayer: _audioPlayer);
    _fixCallbackLookupFailedIssue();
  }

  // https://github.com/luanpotter/audioplayers/issues/344
  void _fixCallbackLookupFailedIssue() {
    if (Platform.isIOS) {
      _audioPlayer
          .monitorNotificationStateChanges(_audioPlayerStateChangeHandler);
    }
  }

  void start(String filename) {
    if (!mute) _audioCache.play(filename);
  }

  void loop(String filename) {
    if (!mute) _audioCache.loop(filename);
  }

  void stop() => _audioPlayer.stop();

  Future<void> dispose() async {
    await _audioPlayer.pause();
    await _audioPlayer.dispose();
  }
}

void _audioPlayerStateChangeHandler(AudioPlayerState state) => null;

BTW ensure this function is outside of Audio class.

void _audioPlayerStateChangeHandler(AudioPlayerState state) => null;

@erickzanardo
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests