ryanheise / just_audio

Audio Player
1.03k stars 652 forks source link

[Android] Sound stops playing when backgrounding app and letting phone go to sleep #1255

Closed corey-finch closed 3 months ago

corey-finch commented 3 months ago

Which API doesn't behave as documented, and how does it misbehave? I am using just_audio version 0.9.38 and playing an audio file from the web using flutter_cache_manager 3.3.1. I'm using an AudioPlayer with a ConcatenatingAudioSource and calling audioPlayer.play.

Minimal reproduction project Clone this repository (or just read the main.dart file) https://github.com/corey-finch/just_audio_bug. This repo just uses the basic example project created via flutter create with minimal code to start a sound effect on the first button tap.

To Reproduce (i.e. user steps, not code)

Error messages There's no error from what I can tell but here is the most recent debug logging before audio cuts out

D/MediaCodec(27380): keep callback message for reclaim
I/CCodecConfig(27380): query failed after returning 7 values (BAD_INDEX)
W/Codec2Client(27380): query -- param skipped: index = 1342179345.
W/Codec2Client(27380): query -- param skipped: index = 2415921170.
D/BufferPoolAccessor2.0(27380): bufferpool2 0xb400007cf55a6d98 : 5(40960 size) total buffers - 1(8192 size) used buffers - 2667/2672 (recycle/alloc) - 9/5332 (fetch/transfer)
D/BufferPoolAccessor2.0(27380): bufferpool2 0xb400007cf55a6d98 : 5(40960 size) total buffers - 1(8192 size) used buffers - 2894/2899 (recycle/alloc) - 9/5786 (fetch/transfer)
D/BufferPoolAccessor2.0(27380): bufferpool2 0xb400007cf55a6d98 : 5(40960 size) total buffers - 1(8192 size) used buffers - 3117/3122 (recycle/alloc) - 9/6232 (fetch/transfer)
D/BufferPoolAccessor2.0(27380): bufferpool2 0xb400007cf55a6d98 : 5(40960 size) total buffers - 1(8192 size) used buffers - 3331/3336 (recycle/alloc) - 9/6660 (fetch/transfer)

Expected behavior Audio playback should continue even when the app is in the background or when the screen is disabled. We want to support the ability to play a background "soundscape" even when the app is not actively in use. The expected behavior is observed on iOS (device can be left with app backgrounded and screen turned off indefinitely and audio will continue to play).

Smartphone (please complete the following information):

Flutter SDK version

 $ flutter doctor   
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel [user-branch], 3.16.1, on macOS 13.6.6 22G630 darwin-arm64, locale en-US)
    ! Flutter version 3.16.1 on channel [user-branch] at /Users/corey/Dev/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.0)
[✓] Chrome - develop for the web
[!] Android Studio (version unknown)
    ✗ Unable to determine Android Studio version.
[✓] Android Studio (version 2022.3)
[✓] IntelliJ IDEA Community Edition (version 2023.3.6)
[✓] VS Code (version 1.89.1)
[✓] Connected device (3 available)
    ! Error: Browsing on the local area network for Old iPhone XR. 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 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)
[✓] Network resources
ryanheise commented 3 months ago

Which API doesn't behave as documented, and how does it misbehave? I am using just_audio version 0.9.38 and playing an audio file from the web using flutter_cache_manager 3.3.1. I'm using an AudioPlayer with a ConcatenatingAudioSource and calling audioPlayer.play.

This isn't a bug unless you can show that it doesn't behave "as documented". The instructions for this section said:

Name here the specific methods or fields that are not behaving as documented, and explain clearly what is happening.

In order to answer this section, you must read the documentation and confirm that the documentation for those specific methods claim that they work in the background, where as when you test them, they do not work as documented.

(Closing as this is not a bug.)

github-actions[bot] commented 3 months ago

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.