ryanheise / just_audio

Audio Player
1.01k stars 619 forks source link

MissingPluginException when trying to run tests #1215

Open jvaleski opened 3 months ago

jvaleski commented 3 months ago

Which API doesn't behave as documented, and how does it misbehave? setUrl() appears to be causing two MissingPluginExceptions to be raised when I run my test via

flutter test test/file_access_test.dart

Minimal reproduction project test/file_access_test.dart

import 'package:flutter_test/flutter_test.dart';
import 'package:just_audio/just_audio.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();
  test("HTTP Access test", () async {
    final player = AudioPlayer();
    await player.setUrl("https://s3.amazonaws.com/404-file.mp3");
  });
}

pubspec.yaml for just_audio and tests

just_audio: ^0.9.36
test: ^1.24.9
integration_test:
  sdk: flutter

To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:

  1. create above file in test dir w/ referenced test code
  2. run tests w/ above command

Error messages

00:01 +0 -1: HTTP Access test [E]                                                                                                                                         
  MissingPluginException(No implementation found for method disposeAllPlayers on channel com.ryanheise.just_audio.methods)
  package:flutter/src/services/platform_channel.dart 332:7                    MethodChannel._invokeMethod
  ===== asynchronous gap ===========================
  dart:async                                                                  _CustomZone.registerBinaryCallback
  package:just_audio_platform_interface/method_channel_just_audio.dart 29:10  MethodChannelJustAudio.disposeAllPlayers
  package:just_audio/just_audio.dart 30:22                                    _pluginPlatform
  package:just_audio/just_audio.dart 1370:38                                  AudioPlayer._setPlatformActive.setPlatform
  package:just_audio/just_audio.dart 1481:17                                  AudioPlayer._setPlatformActive
  package:just_audio/just_audio.dart 803:20                                   AudioPlayer.load
  package:just_audio/just_audio.dart 774:24                                   AudioPlayer.setAudioSource
  package:just_audio/just_audio.dart 687:7                                    AudioPlayer.setUrl
  test/file_access_test.dart 8:18                                             main.<fn>

  MissingPluginException(No implementation found for method init on channel com.ryanheise.just_audio.methods)
  package:flutter/src/services/platform_channel.dart 332:7  MethodChannel._invokeMethod
  ===== asynchronous gap ===========================
  dart:async                                                _CustomZone.registerBinaryCallback
  package:just_audio/just_audio.dart 1370:13                AudioPlayer._setPlatformActive.setPlatform
  package:just_audio/just_audio.dart 1481:17                AudioPlayer._setPlatformActive
  package:just_audio/just_audio.dart 803:20                 AudioPlayer.load
  package:just_audio/just_audio.dart 774:24                 AudioPlayer.setAudioSource
  package:just_audio/just_audio.dart 687:7                  AudioPlayer.setUrl
  test/file_access_test.dart 8:18                           main.<fn>

Expected behavior expecting that things run without the exception issue

Desktop (please complete the following information):

dart --version
Dart SDK version: 3.3.3 (stable) (Tue Mar 26 14:21:33 2024 +0000) on "macos_arm64"

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.5, on macOS 14.4.1 23E224 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.6)
[✓] IntelliJ IDEA Community Edition (version 2022.3.3)
[✓] VS Code (version 1.87.2)
[✓] Connected device (3 available)
[✓] Network resources
mjjoshi commented 2 months ago

@ryanheise can you please let us know how can we resolve this issue

PKiman commented 1 month ago

Same issue here. Unit test fails. But plugin is tagged for ANDROID IOS MACOS WEB support.

https://pub.dev/packages/just_audio

MissingPluginException(No implementation found for method disposeAllPlayers on channel com.ryanheise.just_audio.methods)
  package:flutter/src/services/platform_channel.dart 308:7                    MethodChannel._invokeMethod
  ===== asynchronous gap ===========================
  dart:async                                                                  _CustomZone.registerBinaryCallback
  package:just_audio_platform_interface/method_channel_just_audio.dart 29:10  MethodChannelJustAudio.disposeAllPlayers
  package:just_audio/just_audio.dart 30:22                                    _pluginPlatform
  package:just_audio/just_audio.dart 1340:38                                  AudioPlayer._setPlatformActive.setPlatform
  package:just_audio/just_audio.dart 1451:17                                  AudioPlayer._setPlatformActive
  package:just_audio/just_audio.dart 784:20                                   AudioPlayer.load
  package:just_audio/just_audio.dart 755:24                                   AudioPlayer.setAudioSource
  package:just_audio/just_audio.dart 687:7                                    AudioPlayer.setFilePath
ryanheise commented 1 month ago

@PKiman , what kind of test are you using? A unit test or an integration test?

@jvaleski please take a look at the unit tests included in this repo under just_audio/test/just_audio_test.dart which are working (although admittedly not very idiomatic, currently).

PKiman commented 1 month ago

I am using unit test in another software project.

PKiman commented 1 month ago

These lines are enough to produce the error on MacOS:

flutter clean && flutter test

minimal_test.dart

import 'package:just_audio/just_audio.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

void main() async {
  TestWidgetsFlutterBinding.ensureInitialized();

  group('test group1', () {
    test('Test 1', () {
      final AudioPlayer player = AudioPlayer();
      final durationObj = await player.setFilePath('path_to_audio.m4a');
      player.dispose();
   });
  });
}
ryanheise commented 1 month ago

Have you tried the unit tests in this repository?