Open fourman-alex opened 11 months ago
same issue
This was happening to hundreds of our users: say they used the app hald an hour ago, and in the app they paused the playback... then whenever they make a phone call, and phonecall would end... our app would suddenly start playing audio!! When I looked around, it seems to be connected with Manage audio focus (seems to be happening only on Android, and only when audio is paused), where android system is handing back the 'focus' (who should play next) to the most recent audio app that was playing. This is used for example to re-start your audiobook, after a phonecall. I am investigating further, but did not find a solution yet in audioplayers library. For now I had to listen for the app going into background, and if the audio is paused I completely stop() is. This loses audio progress (eg. that it was 1m:23s into the file), but is an OK price to pay.
This also happens when Android plays some other audio from other apps, For now listening to app going in background works !
late AppLifecycleListener appLifecycleListener;
@override
void initState() {
super.initState();
isLoaded.value = true;
player = widget.player;
appLifecycleListener = AppLifecycleListener(
onPause: () {
player.stop();
player.release();
},
);
}
i want to play audio in the background, so the answer @Afroz-Shaikh is not working for me.
Checklist
Current bug behaviour
If a source was paused, after an incoming call the source will resume playing on its own.
Expected behaviour
The audio should stay paused and not start playing without any user interaction.
Steps to reproduce
nasa_on_a_mission.mp3
and start playingnasa_on_a_mission.mp3
will resume playing, which should not happen.Code sample
Code sample
```dart void main() { } ```Affected platforms
Android
Platform details
No response
AudioPlayers Version
main
Build mode
debug
Audio Files/URLs/Sources
No response
Screenshots
No response
Logs
Full Logs
``` my full logs or a link to a gist ``` Flutter doctor: ``` [✓] Flutter (Channel stable, 3.13.7, on macOS 14.0 23A344 darwin-arm64, locale en-US) • Flutter version 3.13.7 on channel stable at /Users/alexfourman/Development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 2f708eb839 (4 weeks ago), 2023-10-09 09:58:08 -0500 • Engine revision a794cf2681 • Dart version 3.1.3 • DevTools version 2.25.0 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/alexfourman/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.0.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15A507 • CocoaPods version 1.12.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) [✓] VS Code (version 1.84.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.76.0 [✓] Connected device (3 available) • Mi A2 (mobile) • dc00c9 • android-arm64 • Android 11 (API 30) • macOS (desktop) • macos • darwin-arm64 • macOS 14.0 23A344 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 118.0.5993.117 [✓] Network resources • All expected network resources are available. • No issues found! ```Related issues / more information
No response
Working on PR
no way