just_audio
just_audio copied to clipboard
Application crashes when terminated by user on iOS
Which API doesn't behave as documented, and how does it misbehave? just audio 0.9.41
It is crashing if you close the application while audio players are loaded on iOS. It is crashing because flutter disposes the just_audio plugin, which causes the players to be disposed. When players are disposed they send a broadcast event with their current status, which causes a crash report.
Minimal reproduction project
import 'package:flutter/material.dart';
import 'package:just_audio/just_audio.dart';
AudioPlayer? _tapAudioCache;
void main() async{
WidgetsFlutterBinding.ensureInitialized();
runApp( MaterialApp(
title: 'Flutter Demo',
home: Center(
child: ElevatedButton(onPressed: () async{
_tapAudioCache = await initEffectsCache('christmas1.mp3');
_tapAudioCache!.play();
}, child: const Text('Play Sound')),
),
));
}
Future<AudioPlayer> initEffectsCache(String filePath, {double volume = 1}) async {
var player = AudioPlayer();
await player.setUrl('asset:assets/sounds/$filePath', );
await player.setVolume(volume);
return player;
}
To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:
- Launch the application
- Press the 'Play Sound' button
- On the device swipe up and close the application
- An exception will trigger (you can catch it with xcode attached, see screenshot)
Error messages
Exception NSException * "Sending a message before the FlutterEngine has been run." 0x0000600000c90f60
Expected behavior The application should not crash when terminating the application while players are loaded. There is no need for players to report their state when terminating the app. The crash reports are being sent to Apple, Crashlytics etc. ... there is no need for that.
Screenshots
Smartphone (please complete the following information):
- Device: any ios device physical or simulated
- OS: tested on iOS18 but I expect it to happen on any ios version
Flutter SDK version
[!] Flutter (Channel [user-branch], 3.22.3, on macOS 14.6.1 23G93 darwin-arm64, locale en-US)
! Flutter version 3.22.3 on channel [user-branch] at /Users/cristi/Desktop/work/flutter/flutter
Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
! Upstream repository unknown source is not a standard remote.
Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.93.1)
[✓] Connected device (7 available)
! Error: Browsing on the local area network for Constantin’s iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
! Error: Browsing on the local area network for Roxa's iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources
! Doctor found issues in 1 category.
Additional context Add any other context about the problem here.