florent37/Flutter-AssetsAudioPlayer

Uncaught Error: MissingPluginException

Opened this issue · 1 comments

Flutter Version

My version : 3.24.4

Lib Version

My version : ^3.1.1

Platform (Android / iOS / web) + version

Platform : Web Deployed and Test on...

  • Microsoft Edge: Version 130.0.2849.68 (Official build) (64-bit)
  • Google Chrome: Version 130.0.6723.93 (Official Build) (64-bit)
  • Safari 18 on iOS 18

Describe the bug

[√] I can run flutter run -d chrome (tested web only) and have the audio play just fine.
[X] however, when i deploy to the internet using firebase (firebase deploy) no sound is played an the network console prints the founding messages (2 warnings, 1 error).

MissingPluginException(No implementation found for method stop on channel assets_audio_player)
MissingPluginException(No implementation found for method open on channel assets_audio_player)
Uncaught Error: MissingPluginException(No implementation found for method open on channel assets_audio_player)

Flutter doctor

[√] Flutter (Channel stable, 3.24.4, on Microsoft Windows [Version 10.0.22631.4391], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[X] Android toolchain - develop for Android devices
    X Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/to/windows-android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.32)
[!] Android Studio (not installed)
[√] VS Code (version 1.95.1)
[√] Connected device (3 available)
[√] Network resources

Small code to reproduce
main.dart

import 'package:assets_audio_player/assets_audio_player.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State {
  
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: RaisedButton(
            child: Text("open"),
            onPressed: () {
                        AssetsAudioPlayer.newPlayer()
              .open(Audio('assets/sound.mp3'), autoStart: true);
            }
          ),
        ),
      ),
    );
  }
}

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  #...
  assets_audio_player: ^3.1.1
  #...
  assets:
    - assets/sound.mp3
  #...

I have the same problem, so I have done some testing based on @bin2ai's test code. When debugging, I get a very strange behaviour inside the Future _open in assets_audio_player.dart as code lines are skipped after invoking the open method.

I use a local copy, so have added some debugging code (which yet does not help me much).

Code from the invokeMethod:

        final result = await _sendChannel.invokeMethod('open', params); //Break point here. Then press F8

        //Code below this is skipped
        print('Result: $result');
        if (result == true) {
          print('Audio file open ok');
        } else {
          print('Failed to open audio file');
        }

        await setLoopMode(_loopMode);

        _stopped = false;
        _playlistFinished.add(false);

        //Code above this is skipped
        _isBuffering.add(false); //Skips all lines up to this code after invoking the open method above pressing F8
      } on PlatformException {
        final errorHandler = ErrorHandler(
          player: this,
          currentPosition: currentPosition.value,
          playlist: _playlist?.playlist,
          playlistIndex: _playlist?.playlistIndex,
          error: AssetsAudioPlayerError(
            errorType: AssetsAudioPlayerErrorType.Player, message: '',),
        );
        if (onErrorDo != null) {
          onErrorDo!(errorHandler);
        }
      } catch (e) {
        _lastOpenedAssetsAudio = currentAudio; // revert to the previous audio
        _current.add(null);
        _isBuffering.add(false);
        _currentPosition.add(Duration.zero);
        try {
          await stop();
        } catch (t) {
          print(t);
        }
        print(e);
        return Future.error(e);
      }
    }
  }

I have a break point on the invokeMethod. When pressing F8 (Android Studio latest), it skips directly to the line as indicated in the comments in the code snippet (_isBuffering.add(false);).
Then it goes into the catch (e) and catch (t) which then outputs these errors:

MissingPluginException(No implementation found for method stop on channel assets_audio_player)
MissingPluginException(No implementation found for method open on channel assets_audio_player)
RethrownDartError: MissingPluginException(No implementation found for method open on channel assets_audio_player)

dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 329:10 createErrorWithStack
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 265:28 _throw
dart-sdk/lib/core/errors.dart 120:5 throwWithStackTrace
dart-sdk/lib/async/zone.dart 1386:11 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7

Needless to say, no audio is ever played.