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

AudioPlayer._setPlatformActive.setPlatform Null check operator used on a null value #1120

Closed
under3415 opened this issue Nov 11, 2023 · 8 comments
Assignees
Labels
1 backlog bug Something isn't working

Comments

@under3415
Copy link

Which API doesn't behave as documented, and how does it misbehave?
AudioPlayer._setPlatformActive.setPlatform throws "Null check operator used on a null value" error

Minimal reproduction project
"The example"

I cannot reproduce this bug. This occurs "in the wild", I get this error in crashlytics, quite regularly.
Last time on Galaxy A03 Core on Android 12, but no rules, different devices and versions

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

  1. Play a short sound. In vast majority of cases this works fine, but sometimes it errors. This is my code where the error is triggered:
  try {
            await _soundPlayer.setAsset('assets/sounds/change_sides.mp3');
            _soundPlayer.play();
  } catch (ex, st) {
            FirebaseCrashlytics.instance
                .recordError(ex, st, reason: 'soundPlayerSides');
 }

Error messages

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Null check operator used on a null value. Error thrown soundPlayerSides.
       at AudioPlayer._setPlatformActive.setPlatform + 1436(just_audio.dart:1436)

Expected behavior
Handle a null or prevent the null from occurring? I don't really understand what is going on here, does not seem to be related to my code.

Screenshots
N/A

Desktop (please complete the following information):
N/A

Smartphone (please complete the following information):

  • Device: Galaxy A03 Core, but also others
  • OS: Android 12, but also others

Flutter SDK version

just_audio: ^0.9.35
[√] Flutter (Channel stable, 3.13.9, on Microsoft Windows [Version 10.0.22631.2506], locale en-NZ)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Android Studio (version 2022.3)
[√] VS Code (version 1.84.2)
[√] Connected device (3 available)
[√] Network resources

Additional context
Sorry I cannot replicate this. Feel free to close if this is not useful.

@under3415 under3415 added 1 backlog bug Something isn't working labels Nov 11, 2023
@rymesaint
Copy link

this also happen to me

@bthnkckalpamis
Copy link

hi, any updates? @ryanheise @under3415

@ryanheise
Copy link
Owner

I need someone to submit a bug report with a minimal reproduction project and steps to reproduce.

@wangxp423
Copy link

this also happen to me,so how to resolve it ?

@under3415
Copy link
Author

I don't know how to replicate this issue. It happens infrequently in the wild

@louisdeveseleer
Copy link

louisdeveseleer commented Aug 27, 2024

I have the same issue:
_TypeError: Null check operator used on a null value in just_audio.dart in AudioPlayer._setPlatformActive.setPlatform at line 1465 within just_audio

It is not reproducible: it happens in production "in the wild" but not during development.

I haven't been able to identify a specific pattern: it happens on any Android version, and any device (does not happen on iOS).

In the last month, it has affected 5% of my active users (37k) at least one time.

It's been happening at least as far back as May 2023.

@ryanheise If I can provide any extra information or do some tests to help you debug this issue, please let me know!

@under3415
Copy link
Author

under3415 commented Sep 19, 2024

I have resolved these errors by using this approach:

  1. Checking that player is initialized before playing. Note initialized is set to false on dispose to prevent errors when the app is shutting down and the sounds attempts to play from an async call.
  2. Using runZonedGuarded to cach async errors
 Future<void> _initializeAudioPlayer() async {
   //called from initState
    runZonedGuarded(() async {
      _soundPlayer = AudioPlayer();
     //other init settings...
       _initialized = true;
    }, (error, stackTrace) {
      FirebaseCrashlytics.instance.recordError(error, stackTrace, fatal: true);
    });
  }
 @override
  dispose() {
    initialized = false;
    try {
      _soundPlayer.dispose();
    } catch (ex, st) {
      FirebaseCrashlytics.instance
          .recordError(ex, st, reason: 'workoutDispose');
    }
    super.dispose();
  }

 void _loadAndPlaySound(String path, String reason) {
    if (!initialized) {
      return;
    }
    runZonedGuarded(() async {
      await _soundPlayer.setAsset(path);
      _soundPlayer.play(); //intentionally not awaiting here to play async
    }, (error, stackTrace) {
      // Handle the error
      FirebaseCrashlytics.instance
          .recordError(error, stackTrace, reason: reason);
    });
  }

Also, if obfuscating add this to R8 rules

# Just Audio
-keep class com.ryanheise.just_audio.** { *; }
-dontwarn com.ryanheise.just_audio.**

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with just_audio.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants